Hey, JavaScript, you want to inherit.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.