Prototype chain:
Object (constructor) object (Type (object))
var o = {};alert (typeof O); // The result is Objectalert (typeof object); // The result is function
Each object has a property called __proto__ , which is the prototype of this object (O. __proto__)
Objects have prototypes, prototypes are also objects, so prototypes have prototypes.
All the functions are objects, Inheriting from Function.prototype,function.prototype is an object, inheriting from Object.prototype,object.prototype is an object, inheriting from Nullobj is an object, inheriting from Object.prototypefunc tion is an object, inheriting from Function.prototypefunction is a function that inherits from Function.prototype
the access rules for JS members O. Method () First look for the definition of the member in the current type O, and if there is a definition of the member, use the change member directly, and if the member is no longer in the current type, access its prototype (the previous level in the prototype chain) and so on, until the null position
code example:
Do not use inheritance:
var function () { thisfunction() { alert ("Hello"); };} ; var New Person (); var New = = = P2.say); // The result is false
Each new object creates a piece of memory, so P1.say and P2.say are not the same address as the reference.
using prototype inheritance:
var function = { say:function() { alert ("Mr Jing"); }}; var New Person (); var New = "Mr Jing"= = = = P2.say); // The result is truealert (p2.name); // The result is "Mr Jing"
Prototype inheritance in JavaScript