Inheritance problem of javascript prototype chain

I would like to ask why the last instance2.test result in the following set of prototype chain code is h _ 1, br, h _ 2, h _ 3, and h _ 4?

hasn"t an h5 already been push before

?

clipboard.png


test is an instance attribute of the subclass SubType . When var instance2=new SubType () , assign test of instance2 to ["H1", "H2", "h3", "h4"] . Similarly, when you instance1.test.push , you also modify the instance properties of instance1 .

when you visit instance2.name , you can't find the instance property. Then go to the prototype chain and find that SubType.prototype has the attribute name , so return it. Similarly, instance1.name.push also modifies the name attribute of the prototype chain SubType.prototype .

Menu