Function and object in JavaScript

Source: Internet
Author: User

1, first to a section of code:

Console.log (Function);//function function () {[native code]}Console.log (Object);//function Object () {[native code]}Console.log (function.prototype);//function () {}Console.log (Object.prototype);//Object {}Console.log (function.__proto__);//function () {}Console.log (function.__proto__.__proto__);//Object {}Console.log (function.__proto__.__proto__.__proto__);//NULLConsole.log (object.__proto__);//function () {}Console.log (object.__proto__.__proto__);//Object {}Console.log (object.__proto__.__proto__.__proto__);//NULL

Console.log (Function.constructor = = = Function); True
Console.log (Object.constructor = = Function)//True

Conclusion:

A, the constructor of the constructor function is itself, so: function.constructor = = = function; The constructor of the constructor Object is itself, so: object.constructor = = = function PS: All constructors constructor point to Function,function is a top-level function;

b, the __proto__ of the constructor function is an anonymous null function () {};

c, anonymous null function () {} __proto__ points to the prototype of object;

D, the __proto__ of object points to the function of the prototype, that is, anonymous null function functions () {};

Object inherits itself, Funtion inherits itself, object and function inherit each other, that is, object and function are both functions and objects. This is a very special point. All functions are objects, but not all objects are functions.

From know:

Object.prototype is the source of all objects
Object.prototype is only mounted on object function objects
Function.prototype structure from Object.prototype
Function.prototype is just mounted on the function object
Object functions and function functions constructed from Function.prototype
Object literal objects {} Constructed from Object.prototype
Object literal {}.__proto__ (original constructed object) = = = Object.prototype
function functions and custom functions are inherited (constructed) from Function.prototype
Function.prototype and Function.__proto__ (original constructed object) are the same
So, there are first object.prototype, then some function.prototype, and then the function and object functions.

Function and object in JavaScript

Related Article

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.