Concepts and relationships for constructors, instances, and prototypes

Source: Internet
Author: User

Each function belongs to an object, and there is a property called prototype. This property points to an object that we call the prototype object of the current function. Below the prototype object is a property called constructor. This property points to the current function. Functions are also divided into ordinary functions and constructors. Here we talk about constructors. Define a function:

function person (x, y) {this.age = X;this.name = y;
}var xiaoming= New Person ("xiaoming");

Here to create an instance of the object xiaoming is called the person constructor, so that Xiaoming has its own properties and methods, and then xiaoming and person there is no direct intersection (can be understood as xiaoming broke up, hey programmer very difficult ╥. ╥) But each instance object will have a hidden property [[prototype]], which is called __proto__ in Chrome/firefox, and is only for learning and debugging purposes. It points to the prototype object of the constructor.

Concepts and relationships for constructors, instances, and prototypes

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.