Function() function object in JS
欧阳克
欧阳克 2017-06-12 09:29:33
0
3
745

The Object() constructor can be seen as: var Object=new Function();
The Array() constructor can be seen as: var Array=new Function();
.... Then:
Function() constructor can be seen as: var Function=new Function()?
Created itself?
There are other similar native objects, Object.prototype, as the ultimate prototype object of the prototype chain, how was it created? Is it also created by new Object()? But shouldn’t Object.prototype be the first object in the JS native system?
I feel like I can no longer understand the prototype-based thinking of JS. Please give me some guidance...

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all (3)
学习ing

In fact, it is not a chicken-and-egg problem. All objects are actually functions, including the function itself. Let’s talk about the prototype first. The prototype is based on the constructor and __proto__, and these two are included in the prototype, and these three are composed together. A function is created; the prototype chain is based on the direction of __proto__. The prototype chain is bottom-up and based on the principle of proximity. It searches for the desired attributes and forms a prototype chain; so js is a simulated language, which is also the essential difference between it and other languages!

    我想大声告诉你
    1. There is a difference between objects (functions) that can be generated through new and all objects (functions) that need to be generated through new.

    2. Function, Object, etc. can be considered to be provided in the process of js implementation. My understanding is that in order to implement the prototype chain, the browser adds__proto__-->* when providing these functions according to the implementation of the prototype chain. **.prototype. It means that the js environment provides several special objects (functions), and then these objects (functions) are processed in order not to violate the specifications.

    The first one is definitely correct, the second one is my understanding.

      伊谢尔伦
      null | Object---prototype | Function---prototype
        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!