Lodash教程

Lodash before method

语法

_.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.

参数

n (number) − The number of calls at which func is no longer invoked. func (Function) − The function to restrict.

输出

(Function) − Returns the new restricted function.

实例

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

输出

Alarm raised.
Alarm raised.
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4