- 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 - before method
Syntax
_.before(n, func)
Creates a function that invokes func, with the this binding and arguments of the created function, while it's called less than n times. Subsequent calls to the created function return the result of the last func invocation.
Arguments
n (number) − The number of calls at which func is no longer invoked.
func (Function) − The function to restrict.
Output
(Function) − Returns the new restricted function.
Example
var _ = require('lodash'); var raiseAlarm = _.before(3, function(){ console.log('Alarm raised.')}); //Alarm raised will be called two times raiseAlarm(); raiseAlarm(); raiseAlarm(); raiseAlarm();
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
Alarm raised. Alarm raised.
lodash_function.htm
Advertisements