Lodash once method
语法
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.
参数
func (Function) − The function to restrict.
输出
(Function) − Returns the new restricted function.
实例
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
输出