我正在阅读教程,以便了解 _.bind 和 _bindAll:http ://blog.bigbinary.com/2011/08/18/understanding-bind-and-bindall-in-backbone.html
该网站有以下代码
function Developer(skill) {
this.skill = skill;
this.says = function(){
alert(this.skill + ' rocks!');
}
}
var john = new Developer('Ruby');
john.says(); //Ruby rocks!
对比
function Developer(skill) {
this.skill = skill;
this.says = function(){
alert(this.skill + ' rocks!');
}
}
var john = new Developer('Ruby');
var func = john.says;
func();// undefined rocks!
为什么存储对函数的引用然后调用该函数会导致 this 具有窗口上下文?