Lodash教程

Lodash once method

语法

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

参数

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

\>node tester.js

输出

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