Javascript这个关键字里面的函数
这个问题在这里已经有了答案:
因为this值取决于function的调用方式。 closure被调用时没有引用context ,全局上下文是window (在浏览器中)
使用Function.prototype.call在invoked Function.prototype.call时指定this上下文
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/94909.html
