JavaScript's prototype

Source: Internet
Author: User

Prototype Object : Any function has the prototype property, which is a pointer to the function object, and the prototype property contains the properties and methods shared by all instances. All prototype objects have a constructor property, which is a pointer to the function where the prototype property resides.

prototype chain : Each constructor has a prototype object, the prototype object has a Costruct property, a pointer to the constructor, an instance of the constructor has a prototype property, which is an internal pointer to the prototype object. If the prototype of an object A is an instance of object B, then A's prototype object contains a pointer to the B prototype object, so that layers of progression form the chain of instances and prototypes. This is the prototype chain.

prototype chain inheritance : Inheritance is implemented by creating an instance of a constructor, where the child's prototype property equals an instance of the father's constructor, so that the prototype attribute of the child's prototype object points to the father's prototype object. All the attributes and methods that existed in the father's instance are now in the child's prototype object, thus establishing an inheritance relationship.

function parent () {}parent.prototype.parentname= "Da"; function Child () {}child.prototype=new  parent (); Child.prototype.childName="Xiao"; var New Child ();

JavaScript's prototype

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.