Why Object.prototype on the prototype chain Function and Object Function.prototype on the prototype chain are both true

About javascript prototype chain has a question I always wonder:
Why Function instanceof Object and Object instanceof Function are true it?

Instanceof Object // Function -> to true
Object instanceof Function // -> to true
1
2
give the conclusion it (a function and object b refers to what you read on until a):
the essence of Object instanceof Function is a function of a prototype of Object the chain;
Function instanceof Object is the essence of the object b in the prototype chain of Function.

 

I saw this figure is only understood:
(strictly speaking the contents of documents related figures are only the red box)

 

ps: you do not know JavaScript (the volume) 171 screenshots

First is that why the results Object instanceof Function is ture, namely on the Object prototype chain Function.prototype

Function This function is a built-Function.prototype a function, but also as a function of the object, and therefore also defines a function apply, call, bind attributes (or method). The Object delegate goal Object.proto It is this function a, so the results Object instanceof Function is ture.

Come to talk about why the Object.prototype on the prototype chain Function, that Function instanceof Object is ture.

Object这个内置函数的Object.prototype是一个对象b,很多我们经常用到的属性(或者说方法)如:toString、valueOf、hasOwnProperty、isPrototypeOf就是定义在对象b上的。从图上可以看到,Function的委托目标竟然也是函数a(Function.prototype和Function.proto都指向函数a),而函数a的委托目标正是对象b,因此Function instanceof Object为ture。

到上面为止其实都只是看图说话而已,关系都已经在图上表示了,只是我觉得初看图也不好理解,尝试借助文字加强对图的理解而已。

简单来说就是**Object instanceof Function其实就是说函数a在Object的原型链上,
Function instanceof Object就是说对象b在Function的原型链上。**

Function与Object的委托目标都是函数a,而函数a的委托目标是对象b。

以下是我简化的图:


Object instanceof Function的实质就是函数a在Object的原型链上;
Function instanceof Object的实质就是对象b在Function的原型链上。
现在看来,Object.prototype在Function的原型链上与Function.prototype在Object的原型链上都为true其实是一件挺自然的事。

Guess you like

Origin www.cnblogs.com/zhishaofei/p/11704167.html