在 Javascript秘密花园 看到这样一段:
另一个技巧是同时使用 call 和 apply,创建一个快速的解绑定包装器。
function Foo() {}
Foo.prototype.method = function(a, b, c) {
console.log(this, a, b, c);
};
// 创建一个解绑定的 "method"
// 输入参数为: this, arg1, arg2...argN
Foo.method = function() {
// 结果: Foo.prototype.method.call(this, arg1, arg2... argN)
Function.call.apply(Foo.prototype.method, arguments);
};
代码中Function.call.apply该如何理解?解绑定包装器又是干嘛的?
出处:http://bonsaiden.github.io/JavaScript-Garden/zh/#other