【发布时间】:2013-12-19 05:10:45
【问题描述】:
Function.prototype.bind = function(){
var fn = this,
// clone arguments
args = Array.prototype.slice.call(arguments),
// get the first argument, which should be an object, and args will be modified.
object = args.shift();
return function(){
return fn.apply(object,
// why use concat??? why?
args.concat(Array.prototype.slice.call(arguments)));
};
};
...
elem.onclick = Button.click.bind(Button, false);
....
我从这里看到了上面的代码: http://ejohn.org/apps/learn/#86 在学习javascript的同时。代码摘自prototype.js。 cmets 由我添加,而不是来自原始代码。
我的问题是为什么要使用 args.concat(Array.prototype.slice.call(arguments)))?我认为传递参数就足够了。 prototype.js 中的 bind() 必须有其正当理由。请帮助我理解它。谢谢!
【问题讨论】: