function Bar(){
this.name = 'xxx'
this.getName = function(){
console.log(this); // 未调用
}
console.log(this); //未实例化 new 所以指向window 如实例化之后 指向实例 Bar
}
Bar();
var obj = new Bar(); //上述情况实例化之后
obj.getName(); //上述情况 getName 调用下 this指向 Bar
function Bar(){
this.name = 'xxx'
this.getName = function(){
console.log(this); // 未调用
}
console.log(this); //未实例化 new 所以指向window 如实例化之后 指向实例 Bar
}
Bar();
var obj = new Bar(); //上述情况实例化之后
obj.getName(); //上述情况 getName 调用下 this指向 Bar