1 js prototype chain is not open around the topic. Directly on speak.
/ * * * 1. JS in the prototype chain is kind of how? With different class prototype chain and without the class. * / Const util = the require ( 'util' ); function A () { console.info ( "the I AM A" ); } function B () { console.info ( "the I AM B" ); } function C () { console.info ( "the I AM C" ); } util.inherits (B, A); util.inherits (C, B); class {the CA constructor () { console.info ( "I AM the CA" ); } Doca () { console.info ( "Doca" } class CB extends CA{ constructor(){ super(); console.info("i am CB"); } doCB(){ console.info(" do CB "); } } class CC extends CB { constructor(){ super(); console.info("i am CC"); } doCC(){ console.info(" i am doCC"); } } //原型链继承如下: var c = new C(); console.info( c.__proto__ ===C.prototype); console.info (c .__ therefore __.__ proto__ === B.prototype); console.info (c .__ therefore __.__ therefore __.__ proto__ === A.prototype); console.info (c .__ therefore __.__ therefore __.__ therefore __.__ proto__ === Object.prototype); console.info (c .__ therefore __.__ therefore __.__ therefore __.__ therefore __.__ proto__ === null ); // class var cc = new CC (); console.info (cc .__ proto__ === CC.prototype); console.info (cc .__ therefore __.__ proto__ === CB.prototype); console.info (cc .__ therefore __.__ therefore __.__ proto__ === CA.prototype); console.info (CC .__ proto __.__ proto __.__ proto __.__ proto__ === Object.prototype); console.info (CC .__ proto __.__ proto __.__ proto __.__ proto __.__ proto__ === null ); // The following is a class hierarchy . class and non-class are different console.info ( "Class Hierarchy" ); console.info (C.prototype.constructor === C); // prototypes of the configuration C = itself console.info (C .__ proto__ = the Function.prototype ==); // the __proto__ all classes of prototype points Function, i.e. the main configuration of the prototype. console.info (Function .__ proto__ === Function.prototype); // console.info ( "class inheritance relationship with the class" ); console.info (CC .__ proto__ === CB); //CC __proto__ with the class point, cb, eventually most wanted Function prototype. console.info (CC .__ proto __.__ proto__ === CA); console.info (CA .__ proto__ === Function.prototype);
Prototype chain to keep in mind the following points:
1. Every thing has __proto__
2. Prototype prototype class = class. construct the prototype class = class.
3. Small c prototype prototype of the __proto__ = C, C of __proto __ = B and prototype prototype, the prototype __proto__ B = A prototype of the prototype A = __proto__ Object and Object of the prototype _ _proto__ = null; this is the prototype chain, it is very simple.
4. an inherited class, CC of __proto__ = CB, CB of __proto__ = CA, CA in __proto__ = Function prototypes.
Util.inherits when using inheritance, C, B, A, Function Function equal to the __proto__ prototype.
As long as all the above in mind, more practice, one can grasp the prototype chain.
If you have not read the above, you can refer to: https://blog.csdn.net/m0_37589327/article/details/78655038