Lodash教程

Lodash bind method

语法

_.bind(func, thisArg, [partials])
Creates a function that invokes func with the this binding of thisArg and partials prepended to the arguments it receives.

参数

func (Function) − The function to bind. thisArg (*) − The this binding of func. [partials] (...*) − The arguments to be partially applied.

输出

(Function) − Returns the new bound function.

实例

var _ = require('lodash');
var updateMessage = function(message) {
   return this.name + ' : ' + message;
}
//Bind this with object provided
updateMessage = _.bind(updateMessage, {name: 'BinderObject'}, "Welcome");
var result = updateMessage();
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

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