_ PROTO _ and prototype

Source: Internet
Author: User

The _ PROTO _ attribute of an object and its internal attribute [[prototype] point to the same value (usually referred to as the prototype ), the prototype value can be an object value or null (for example, object. prototype. the value of _ PROTO _ is null ). this attribute may cause some errors, because the user may not know the particularity of this attribute and assign values to it, thus changing the prototype of this object. to access the prototype of an object, use the method object. getprototypeof.


When an object is created, its _ PROTO _ attribute and internal attribute [[prototype] point to the same object (that is, the prototype attribute of its constructor ). changing the value of the _ PROTO _ attribute also changes the value of the internal attribute [[prototype], unless the object is not extensible.


What is internal properties: http://my.oschina.net/xinxingegeya/blog/290167


Be aware that _ PROTO _ is not the same as prototype, since _ PROTO _ is a property of the instances (is an instance attribute) (objects ), whereas prototype is a propertyThe constructor FunctionsUsed to create those objects.

 

Consider another object called Monkey and use it as a prototype when creating objectsThe human () constructor.

VaR monkey = {feeds: 'banas', breathes: 'air'}; Function Human () {} human. prototype = monkey; // use the monkey object to override the prototype attribute var developer = new human (); developer. feeds = 'pizza'; developer. hacks = 'javascript '; console. log (developer. hacks); // javascriptconsole. log (developer. feeds); // pizzaconsole. log (developer. breathes); // airconsole. log (developer. _ PROTO _ = monkey); // trueconsole. log (typeof developer. _ PROTO _); // objectconsole. log (typeof developer. prototype); // undefinedconsole. log (typeof developer. constructor. prototype); // objectconsole. log (typeof developer. constructor); // Function


The secret link is exposed in most modern JavaScript environmentsThe _ PROTO _ Property(The word "Proto" with two underscores before and two after ).

Be aware that_ PROTO _ is not the same as prototype, Since _ PROTO _ is a property of the instances (objects), whereasPrototype is a property of the constructor functions used to create those 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.