JS Prototype Object

Source: Internet
Author: User

What is a prototype object?

In JS, each created function has a prototype attribute, which points to an object, which is the prototype object

function

Results from the Chrome browser:

  

What are prototype objects capable of?

First, when you call a function with new, an object instance is created and returned to this object

You can see that a is an object named Lla , with a __prototype__ attribute (described later), which can be thought of as empty; why is it empty? Because the inside of the constructor is empty;

How can we make it not empty?

  

OK, Christina 18 of the handsome pot thick line up. Cough.

The This in the constructor is pointed to B in the new call, so B has two attributes, age,name;

Back to the question, what's the use of prototype objects?

  

B is an instantiated object, and through the code above we find that B has not changed, but it can access the prototype object

The method, so. The role of the prototype object comes out, you can add a variety of shared properties for your instantiated objects and

method, these properties and methods are shared by all instances.

JS Prototype Object

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.