var o = {
x: 10,
doIt: function doIt() {
var x = 20;
alert(x);
alert(this.x);
setTimeout(function() {
alert(this.x);
}, 10);
}
};
o.doIt();
第一个弹出20,第二个弹出10都好理解,请问为什么最后一个是undefined。谢谢!
...全文
15410打赏收藏
this作用域问题
var o = { x: 10, doIt: function doIt() { var x = 20; alert(x); alert(this.x); setTimeout(function() { alert(this.x); }, 10); } }; o.doIt(); 第一个弹出20,第二个弹出10都好理解,请问为什么最后一个是undefined。谢谢!