Implementation of JavaScript object-oriented inheritance

Source: Internet
Author: User

1<script type="Text/javascript">2 function Animal () {3       This. species="Animal";4  }5 function Cat (name,color) {6      This. name=name;7      This. color=color;8 }9 //apply assigns the constructor of the parent class object to the subclass, Animal.apply (this,arguments);Ten function Cat (name,color) { One       This. name=name; A       This. color=color; -Animal.apply ( This, arguments); -  } the  varcat1=NewCat ("Mao","Yellow"); - alert (cat1.species); -  - //Prototype Sub-object prototype Prototype assigns the parent class object and assigns the constructor of the subclass object prototype to the child class +Cat.prototype =NewAnimal (); -Cat.prototype.constructor=Cat; + varcat1=NewCat ("Mao","Yellow"); A alert (cat1.species); at</script>

Implementation of JavaScript object-oriented inheritance

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.