Prototype_javascript tips on JavaScript objects (object)

Source: Internet
Author: User
Each object in JavaScript has a prototype. Try this:
Copy Code code as follows:

var Richard = new Object ();
Alert (typeof (Richard.prototype));

The result is depressing, the browser bounce out is undefined ...

What the hell is going on here?

Look at one more example:
Copy Code code as follows:

function Richard () {}
Alert (typeof (Richard.prototype));

The above example seems to show that only the function object has prototype, and the general object is not prototype, what is the truth?

One more thing, we'll see:
Copy Code code as follows:

var Richard = new Object ();
alert (richard.__proto__);

Are you clear?

In fact, we all have a misunderstanding, is that the formation of Javascript objects prototype chain prototype is a name prototype attributes, and is accessible. In fact, the prototype of Javascript and the attribute named prototype at the beginning have nothing to do with, it is two different things.

For ordinary objects, we can only access the prototype inherited from object objects by __proto__ such attributes;

For a function object, when it is established, the prototype of the function object has been assigned to the prototype property.

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.