日期:2014-05-16 浏览次数:20495 次
function f(){
var t = 'a';
return function fn(){
alert(t)
alert(this.t);
var t = 123;
alert(t);
alert(this.t); //this == window对象
};
}
f()()fn = {
a: 1,
b: function(){
console.info(a);
console.info(this.a);
},
c: function(){
var t = 1;
var _this = this;
//var a = 1; //local scope (1)
//a = 123; //golble scope (2)
return function(){
console.info(t); //闭包scope情况
//this == window对象,当(1)处放开时this.a返回undefined,(2)放开时返回123
console.info(this.a)
console.info(_this.a)
}
}
};
fn.c()()function Test() {
console.log(this);
}
Test(); //window
new Test();//Object