我正在閱讀本文 - http://www.robertsosinski.com/2009/04/28/binding-scope-in-javascript/ - 在其中創建自定義綁定函數。javascript自定義作用域綁定函數
Function.prototype.bind = function(scope) {
var _function = this;
return function() {
return _function.apply(scope, arguments);
}
}
alice = {
name: "alice"
}
eve = {
talk: function(greeting) {
console.log(greeting + ", my name is " + this.name);
}.bind(alice) // <- bound to "alice"
}
eve.talk("hello");
// hello, my name is alice
我的問題是這條線在particlar
return function() {
return _function.apply(scope, arguments);
}
爲什麼在_function.apply(範圍參數)的回報;那裏?它在做什麼和返回什麼? 我刪除了返回,它仍然有效。