function E () {};function Createpro (PRO) {//Mode 1return object.create (PRO);//mode 2return {__proto__: pro};//mode 3e.prototype = Pro;return new E ();} This is the main function of the inheritance, in order to construct the prototype attribute of the inherited class//There are three methods//The first is the ECMA5 of the object of the method///The second is the use of FF Chrom private properties//The third is to instantiate an empty constructor
var A = function () {}; A.prototype.showa = function () {console.log (' hello ' +this.propa);}; A.prototype.propa = ' a ';//This is the most basic class Avar B = function () {}; B.prototype = Createpro (A.prototype); B.prototype.constructor = B; B.PROTOTYPE.SHOWB = function () {console.log (' hello ' +this.propb);}; B.PROTOTYPE.PROPB = ' B ';//This is the class that inherits a Bvar C = function () {}; C.prototype = Createpro (B.prototype); C.prototype.constructor = C; C.PROTOTYPE.SHOWC = function () {console.log (' hello ' +this.propc);}; C.prototype.propc = ' c ';//This is the class that inherits B cvar cexp = new C;console.log (CEXP);//This is instantiated C
This is the chrom, the clear structure diagram.
You can clearly see the inheritance of an object.
Has fun O (∩_∩) o
Hey, JavaScript, you want to inherit.