Underscore.JS bind方法 语法 _.bind(function, object, *arguments)JavaScriptCopy bind方法帮助将函数中的this替换为传递对象的引用。请参见下面的示例。 示例 var _ = require('underscore'); 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);JavaScriptCopy 将上述程序保存在 tester.js 中。运行以下命令来执行此程序。 >node tester.jsJavaScriptCopy 输出 BinderObject : WelcomeJavaScriptCopy