Why does typeof function return “function”?

大城市里の小女人 提交于 2020-01-11 04:49:26

问题


If both array and function are object subtypes, then why does typeof function return "function" and typeof array return "object"?


回答1:


Because the specification defines different behaviour for typeof when it interacts with objects implementing [[Call]] (i.e. functions).




回答2:


Very ugly, yet correct answer: because ECMAScript specification says so. Keep in mind that on the low level, every array is basically a mere object with "length" property.

If you want to check if given object is actually an array, use Array.isArray.



来源:https://stackoverflow.com/questions/42467581/why-does-typeof-function-return-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!