这在javascript构造函数中

ray*_*ray 0 javascript constructor

function Foo() {  
    alert(this === a);//return false!   **why this is not equal a?**  
}  
var a = new Foo();//create a new object
Run Code Online (Sandbox Code Playgroud)

foo是一个构造函数,为什么'Foo'中的这个与'a'不相等.

jfr*_*d00 6

a当你在构造函数中时,尚未发生对变量的赋值.事件的顺序是:

  1. 创建一个新对象
  2. 运行构造函数
  3. 将新对象分配给变量a.