What does the new operator do? Two in a row, to sum up, or it won’t or it won’t

New goes through four stages: 1. Create an empty object

let obj = new Object(a);Copy the code

2. Link to the prototype

Prototype: obj->Func. Prototype ->Object. Prototype ->null

obj.__proto__ = Func.prototype;
Copy the code

3. Bind this (make this in Func refer to obj and execute the body of Func.)

let result = Func.call(obj);
Copy the code

Func returns obj as a new object. Func returns obj as a new object. Func returns obj as a new object. Otherwise result is returned as a new object.

if (typeof(result) == "object"){
  func=result;
}
else{
    func=obj;
}
Copy the code