jsGarden でこのコードに出くわしましたが、連結する意味がわかりませcall
んapply
。どちらも特定のコンテキスト オブジェクトで関数を実行しますが、なぜ連鎖できるのでしょうか?
function Foo() {}
Foo.prototype.method = function(a, b, c) {
console.log(this, a, b, c);
};
// Create an unbound version of "method"
// It takes the parameters: this, arg1, arg2...argN
Foo.method = function() {
// Result: Foo.prototype.method.call(this, arg1, arg2... argN)
Function.call.apply(Foo.prototype.method, arguments);
};