new关键字如何强制this关键字指向JavaScript中新创建的对象?

how does new keyword force this keyword to point to the newly created object in JavaScript?

请问我是javascript世界的初学者,在new关键字指向新创建的对象这一点上我停止研究了,让我们写一些代码然后问我的题。

function Employee(name) {
    this.name = name;
}

var x = new Employee("youhana");

new 关键字如何强制此关键字指向 x 对象,尽管表达式没有到达末尾,我的意思是

var x = new Employee("youhana");

首先,=操作数会等待new Employee("youhana");的表达式求值结束,然后将这个表达式的最终值赋值给[=15] =] 这将是对象, 另一个例子:

function Book(){
**/*at this point, there's is no relation between the new object that will be created after this block of code ended, so how new keyword in this point knew that the new object  **will** be obj and **this** will point to it?*/**
}

var obj = new Book();

表达式的顺序:

1) 使用Constructor.prototype作为原型创建了一个新的空对象

x=Object.create(Employee.prototype);

2)构造函数被调用,绑定新对象如下:

Employee.call(x);

3)表达式returns

function new_obj(of){
  var obj=Object.create(of.prototype);
  of.call(obj);
  return obj;
}

var x=new_obj(Employee);
//equals
var x=new Employee();