1. Create an empty object, and the this variable references the object, and also inherits the prototype of the function. 2, properties and methods are added to the object referenced by this. 3. The newly created object is referenced by this and the last implicitly returns this.
var person = function (name) {
var this = {};
THIS.name = name;
This.say = function () {
Return "I am" + this.name;
};
return this;
}
The simple understanding is:
var obj = new Base ();
The equivalent of running the following code, what does the new operator do? In fact, it's very simple, it's done three things.
var obj = {};
obj.__proto__ = Base.prototype;
Base.call (obj);
In the first line, we created an empty object, obj.
In the second line, we point the __proto__ member of this empty object to the base function object prototype member object
In the third line, we replace the this pointer of the base function object with obj and then call the base function, so we assign an ID member variable to the Obj object, which is the value of "base"
JS's new operator