function Foo() {
alert(this === a);//return false! **why this is not equal a?**
}
var a = new Foo();//create a new object
foo是一个构造函数,为什么这个在'Foo'中与'a'不相等。this in javascript构造函数
function Foo() {
alert(this === a);//return false! **why this is not equal a?**
}
var a = new Foo();//create a new object
foo是一个构造函数,为什么这个在'Foo'中与'a'不相等。this in javascript构造函数
当您在构造函数中时,对变量a
的赋值尚未发生。事件的顺序是:
a
。
很好的解释jfriend00 – david
@大卫好的,非常感谢。 – ray
@KooiInc提醒真实?我在萤火虫中运行代码,它提醒虚假。 – ray