Why in JavaScript both “Object instanceof Function” and “Function instanceof Object” return true?

前端 未结 7 1162
梦如初夏
梦如初夏 2020-11-27 03:33

Why in JavaScript do both Object instanceof Function and Function instanceof Object return true?

I tried it in Safari WebInspe

相关标签:
7条回答
  • 2020-11-27 04:16

    The most badass property is actually that Function is an instance of itself. Function instanceof Function returns true.

    It is nicely explained in Kannan's The Surprisingly Elegant Javascript Type Model, at http://web.archive.org/web/20140205182624/http://vijayan.ca/blog/2012/02/21/javascript-type-model

    Quote at the end of the explanation:

    Yes, this means that Function is an instance of itself (naturally, since it’s a function, and thus an instance of Function). This is something we’ve all been dealing with, knowingly or not, for a long time now – all constructor functions are regular functions and thus instances of Function, and Function itself is just the constructor function for constructing other functions, so it too is an instance of Function.

    0 讨论(0)
提交回复
热议问题