When I read a blog post, I tested the prototype chain of JavaScript, the prototype object, and found that each constructor (assigned to a prototype ) New object has its own independent prototype object __proto__.
Prototype and __proto__ point to the same object, one is "class" above, and the other is "pair like" above. Prototype literally "type" means that this represents a "class", a category, a collection, not a specific one.
Similar to the relationship between classes and objects in the C + + language. And __proto__ is based on the specific class "prototype", instantiated to deal with a specific object, through the prototype new different objects __proto__ are independent of each other.
It seems wrong!! See
Wrong, wrong, the original test code below the understanding of the wrong. When we assigned S.name, we did not change to the Name property of the S.__proto__ object. Instead, the Name property is added to the S object. When its output is s.name,
Did not go to s.__proto__ above the name attribute, but directly on the S object itself found on the Name property , so do not upward in the s.__proto__ prototype chain to find the name attribute.! I just got it wrong, but it's a good reaction.
The test code is as follows:
function Fun () { //constructor}; Fun.prototype = {name: ' YSR '};var s = new Fun (), s.name = ' pxk '; Console.log (s.name);//pxkvar t = new Fun (); CONSOLE.L OG (t.name); Ysr
JS prototype object, each new object has a separate prototype object __proto__