This code generates x is not definedJS查询 - 全局的window对象
var myobj1 =
{
x:9,
myfunction:function()
{
if(this === window)
alert("x is not Defined");
else if (this === myobj1)
alert(this.x);
else
alert("Error!");
}
}
function test()
{
setTimeout(myobj1.myfunction, 1000);
}
test();
Whereas this code generates x=9 as output
var myobj1 =
{
x:9,
myfunction:function()
{
if(this === window)
alert("x is not Defined");
else if (this === myobj1)
alert(this.x);
else
alert("Error!");
}
}
function test()
{
setTimeout(function()
{
myobj1.myfunction()
}, 1000);
}
有人能解释我为什么“如果不是在测试方法中使用回调方法则全局窗口对象被称为”和“这种情况下回调方法的意义是什么”?