Use the new operator to include the following five steps (the system automatically completes it for you):
1. Create an Object
var obj = new Object();
2. Point the object's __proto__ property to the prototype object of the constructor object
obj.__proto__ = Object.prototype;
3. Point the this pointer to the object
4. Executing the constructor internal code
this.name = name;console.log(this.name);
5. Return the object
return obj;
So:
function Foo (name) { this. Name= name; Console.log (this); Console.log (this. name); } var New Foo ("Wang"); var fn = Foo ("Li");
I want to differentiate myself.
Suoz
Links: https://www.zhihu.com/question/60778790/answer/180524294
Source: Know
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Some questions about JavaScript new