JS Advanced--function prototype chain

Source: Internet
Author: User

Basic concepts

1. Functions can be called by function new, so functions can be referred to as constructors, and the function that is new is called an object.

2, function is a constructor, then there must be a prototype, its prototype is an empty function

3. The prototype object of the function prototype object ultimately points to the Object.prototype

Prototype chain diagram

Prototype chain diagram derived from the above basic concepts

1, the person constructor, since it is a function, then certainly can be created through function, then can be used as an object

2, P object or Function object, the last point is Object.prototype

The relationship between object and function

The relationship is actually more complex, can be detected by the INSTANCEOF keyword

1, the object constructor is instantiated by the function constructor (the object constructor is definitely also a function, since the function is the object, it can be created by the function)

2, function itself is a constructor, since it is also can be created by the functions constructor (this equivalent to create their own)

3, the following returns are true

<Script>    //instanceof: Determines whether the prototype of the constructor exists on the prototype chain of the object    //function--> Function.prototype----> Object.prototype----> NullConsole.log (FunctioninstanceofObject); //whether the Object.prototype is on the prototype chain of functionConsole.log (FunctioninstanceofFunction);//whether the Function.prototype is on the prototype chain of Function    //Object--->function.prototype---->object.prototype----->nullConsole.log (ObjectinstanceofFunction);//whether the Function.prototype is on the prototype chain of objectConsole.log (ObjectinstanceofObject);//whether the Object.prototype is on the prototype chain of Object</Script>

Prototype chain diagram drawn from the above relationship

JS Advanced--function prototype chain

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.