Prototype __proto__ Function

Source: Internet
Author: User

Each function We create has a prototype property, which is a pointer to an object. (Note: The function only has the prototype attribute)

Each object has a __proto__ property.

In JS if the A object is constructed by the B function, then a.__proto__ = = = B.prototype

So:

(1). __proto__ = = = Number.prototype//true

http://blog.csdn.net/aitangyong/article/details/44837655

conclusion 1:object.prototype is just an ordinary object, it is the top of the JS prototype chain. [JavaScript]View Plaincopy
    1. (typeof object.prototype) = = = Object; //true
    2. object.prototype.__proto__=== null; True
    3. Object.prototype.prototype = = = Undefied; //true
Object.prototype is just a normal object (the normal object has no prototype attribute, so the value is undefined), Object.prototype is the top of the JS prototype chain, its __proto__ is null (there is __proto __ property, but the value is null, because this is the top of the prototype chain).Conclusion 2: In JS If the A object is constructed by the B function, then a.__proto__ = = = B.prototype. [JavaScript]View Plaincopy
    1. function person ()
    2. {
    3. }
    4. var obj = {};
    5. Alert (obj.__proto__ = = = Object.prototype); //true
    6. Alert (person.__proto__ = = = Function.prototype); //true
The objects in JavaScript are created by object, and functions are created by function.Conclusion 3: The built-in object is actually a function object, which is created by functions. [JavaScript]View Plaincopy
    1. object.__proto__ = = = Function.prototype;
conclusion each object or function in 4:js has a __proto__ property, but only the function object has the prototype property. [JavaScript]View Plaincopy
    1. //function object   
    2. function person ()   
    3. {  
    4.        
    5. }  
    6.   
    7. //  normal object   
    8. var obj = {};   
    9.   
    10. Obj.__proto__ === object.prototype;//true  
    11. obj.prototype === undefined;
    12. person.__proto__ === function.prototype; true  
    13. person.prototype !== undefined;
We know that JavaScript is inherited through prototype implementations. If Obja, OBJB are created by cfunction, then the conclusion 2,obja.__proto__ = = = objb.__proto__ Cfunction.prototype, which means that both Obja and OBJB objects inherit the prototype of Cfunction.The prototype chain is based on __proto__, and the inheritance is implemented by prototype. conclusion 5:function.prototype is a special case, it is a function object, but there is no prototype property. All other functions have the prototype property. [JavaScript]View Plaincopy
    1. (typeof function.prototype) = = = Function; True
    2. Function.prototype.prototype = = = undefined; //true

Conclusion 6: The built-in function is also a functional object, which is created by itself. [JavaScript]View Plaincopy
    1. (typeof function.__proto__) = = = Function; True
    2. function.__proto__=== Function.prototype; //true
The function object, which is constructed by itself through function functions.Conclusion 7: The function is also an object because function.prototype__proto__ points to object.prototype. [JavaScript]View Plaincopy
    1. (typeof function.prototype.__proto__) = = = "Object"; True
    2. function.prototype.__proto__=== Object.prototype; //true

Finally, the prototype chain is based on __proto__, and the inheritance is implemented by prototype.  Each object has a __proto__ property, and the object on the prototype chain is linked together by this __proto__ property! For an object on the prototype chain, obj, the procedure for accessing the Obj.xxx property (the method is also a property) is to access it if it has a xxx property, or, if not, to find the first-level prototype object of its prototype chain through the __proto__ property, to see if it has a XXX attribute, so recursive lookup, Until you find the XXX attribute or the Object.prototype object at the top of the prototype chain.The function has the prototype property, which is an object type. When function A creates object B, the __proto__ of the B object points to A.prototype, which is the inheritance of JavaScript.

Prototype __proto__ Function

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.