Javascript this keyword inside functions
This question already has an answer here:
Because value of this is determined by how function is called.. closure is called with no reference of context and global context is window (in Browser)
Use Function.prototype.call to specify this context while function is invoked
var car = {
brand: "Nissan",
getBrand: function() {
var closure = function() {
console.log(this.brand);
console.log(this);
};
return closure.call(this);
}
};
car.getBrand();
链接地址: http://www.djcxy.com/p/94910.html
上一篇: 通过数据ID选择和样式对象
下一篇: Javascript这个关键字里面的函数
