- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
Lodash - once method
Syntax
_.once(func)
Creates a function that is restricted to invoking func once. Repeat calls to the function return the value of the first invocation. The func is invoked with the this binding and arguments of the created function.
Arguments
func (Function) − The function to restrict.
Output
(Function) − Returns the new restricted function.
Example
var _ = require('lodash'); var create = function(){ console.log('Object Created.')}; var init = _.once(create); init(); init(); init(); init();
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
Object Created.
lodash_function.htm
Advertisements