SoFunction
Updated on 2025-04-06

javascript new the essence of an object

I used to know these things myself, but I couldn't explain them, and I didn't go into them in depth. When I was watching "Understanding JavaScript" today, I saw the author's description and the "toilet" suddenly opened.

The excerpt is as follows, and the author says it very clearly:


The process of creating an object with the form var anObject = new aFunction() can actually be divided into three steps:

The first step is to create a new object;
The second step is to set the built-in prototype object of the object to the prototype object referenced by the constructor prototype;
The third step is to call the constructor as this parameter to complete the initialization work such as member settings.