I recently saw a post on prototype chain disconnection in the Forum. The original Article is as follows:
Var sound = {echo: function () {alert ("sound") ;}}; function Person () {this. name = "name _" ;}; Person. prototype = sound; // ---- bind it earlier ---- var fo1o = new Person (); var xxxxxx = Person. prototype; // ---- bind later ----?? Xxxxxx. yyyy = "yyyy _"; alert (fo1o. echo); // alert (undefined); alert (fo1o. yyyy); // alert (undefined ); //////////////////////////////////////// //////////////////////////////////////// /// // var sound = {echo: function () {alert ("sound") ;}}; function Person () {this. name = "name _" ;}; var fo1o = new Person (); Person. prototype = sound; // ---- bind it later ---- var xxxxxx = Person. prototype; // ---- bind later ----?? Xxxxxx. yyyy = "yyyy _"; alert (fo1o. echo); // alert (function (){....}); alert (fo1o. yyyy); // alert ("yyyy _"); // Why alert (fo1o. yyyy) will be affected.
The alert comment here is reversed, but this is not the point. Why is the second alert comment undefined? Later, I conducted an experiment to test the following content:
1. alert (fo1o. name); // name _
2. Person. prototype. name = '_ name'; alert (fo1o. name); // name _
3. Person. prototype. name = '_ name'; var fo2o = new Person (); alert (fo2o. name); // name _
The above three experiments are mainly to test whether prototype can modify the original attributes of an object. The result is no longer possible, because in fact, in addition to the inherent (that is, when declared) attributes and methods of each object, there is also a prototype object, and prototype is mainly used to expand the functions of the original object. That is to say, if you access an object's attributes, you must first find them in the inherent attributes. If you cannot find them, go to the properties in the prototype object. For details, see the following two figures:
The first graph declares a class Person, which has an inherent attribute name and a prototype attribute age, and then declares the object a of a Person, then its name attribute is located from the Person class? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> encrypt/ytcTE2rTmu7nKx9K70fmjrNXiwO +/ydLUsNFwcm90b3R5cGW/tNf20ru49ta41euho8v50tTL + encrypt + decrypt/decrypt Example/O5ss/txNq05sHLo6zL/MPHtcTBqs + 1vs274cfQts + example/D5tf2tcTI/example + example/example = "hello, world", then how to pass Pe What if the rson object accesses the name attribute of prototype?
This is the end of my understanding. If any of the above statements is incorrect, please let me know. Thank you.