In the following code, we can see that the prototype object of prototype
Rabbit and the object prototype of Rabbit instance object r1 r1.__proto__
have an constructor
attribute:
In many cases, we need to manually use the constructor attribute to point back to the original constructor. For example,
Rabbit
there is only one method in the constructor just nowsing
. If we want to put multiple methods intoRabbit
it, such as the following:
At this time, we have Rabbit
two methods inside, but! If we have many, many methods to put in Rabbit
it, can we consider wrapping all these methods in one object?
The structure is much clearer in this way, but let's see what the consequences are.
Let's renew a new r1, and then see what the r1.__proto__
sum Rabbit.prototype
looks like at this time :
OMG! ! They no longer point to the original Rabbit constructor! !
This is certainly not, this is the case r1.__proto__
and Rabbit.prototype
can not find their creators (who is also the Rabbit constructor), so weManually refer back to the constructor:
That's it!