JavaScript中Function和Object的关系

jsobj

  • Function.__proto__指向Function.prototype,这导致:
Function.constructor === Function
Function instanceof Function == true

即Function是它自己的构造器。

  • Object.__proto__指向Function.prototype,即Object也是Function构造的实例,因此有:
Object instanceof Function == true

同时也等价于:

Object.constructor === Function

而Function.prototype.__proto__又是指向Object.prototype,即Function.prototype是Object构造的实例,因此有:

Function instanceof Object == true
Object instanceof Object == true
  • Foo.__proto__指向了Function.prototype,可以看到自定义的函数Foo其实就是Function的一个实例:
Foo instanceof Function == true

参考:

This entry was posted in JavaScript. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>