When the constructor in js uses new to create an object, what is the relationship between this and the new object?

JavaScript Advanced programming (3rd Edition) P144
the meaning expressed in (2). It"s not what I understand.
-reference elevation content start-

English explanation
To create a new instance of Person, use the new operator. Calling a constructor in this manner
essentially causes the following four steps to be taken:

  1. Create a new object.
  2. Assign the this value of the constructor to the new object (so this points to the new object).
    PS: (assign the value of the constructor"s this to the new object)
  3. Execute the code inside the constructor (adds properties to the new object).
  4. Return the new object.

-reference elevation content end-
here is my understanding of the steps to call the constructor using the new keyword.
(1). Var newobj = {}; / / first create a new temporary object
(2) .newobj.call (newobj); / / execute the constructor in the scope of the new object.
that is, assign newobj to this. The book says the opposite. Assign the value of the constructor"s this to the new object. How to understand this sentence?


During the execution of

js, not all the code is implemented by js. The book is about the underlying implementation.
now that you have explained the process of new in call, what js code do you use to explain the implementation of call?

< hr >

(1) opens up an area in memory.
(2) this points to this area address.
(3) manipulate this area.
(4) returns the address of this area.


The

new operator can simulate
function F () {}
function new () {

like this
var obj = Object.create(F.prototype);
var ref = F.apply(obj, arguments);
if(Object(ref) === ref) {
    return ref
} else {
    return obj;
}

}
this is assigned to obj or obj is assigned to this. In fact, they are all just references indicating that they point to the same place.
you may think that which address overrides which address, but this is not the case, because this is dynamically assigned at run time.
that is to say, the value of runtime this, that is, the value of obj, non-runtime this does not allocate memory, so there is no one assigning it to whom

.
Menu