[Front-end JS Learning notes] JavaScript prototype objects

Source: Internet
Author: User
First, Concept introduction

  Prototype Object :

The prototype object. In JavaScript, each object inherits another object, which is called a prototype object. Except for null , it does not have its own prototype object.

All properties and methods on the prototype object can be shared by the derived object. A prototype object is automatically assigned through the instance object of the constructor instance. Each one

The prototype property of the constructor is the prototype object of the instance object.

Ii. Use of prototypes

           

For example, an attribute color is added to the source object of animal, and the result is shared by the instance object Bear1, Bear2. If you change the color value, it is reflected on each instance object.

Three, the problem of the prototype solution

If you do not use prototypes, let's look at the following uses. Animal object has the say method, to different instances out of the object, this method provides the same function, but made a trip Bear1.say = = = Bear2.say comparison, return false.

The description does not pass the property, method, which is based on the prototype object, that is, the function can be internally customized properties, methods, all instantiated objects will generate these two objects, and can not be shared, a little waste of system resources.

[Front-end JS Learning notes] JavaScript prototype objects

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.