简体   繁体   English

JavaScript函数的正确类型是什么?

[英]What is the correct typeof a JavaScript function?

Most people know that all functions in JavaScript are actually objects, but why is it that typeof function() {} returns function instead of object ? 大多数人都知道JavaScript中的所有函数实际上都是对象,但为什么typeof function() {}返回function而不是object By this logic, why does typeof [] not return array ? 通过这个逻辑,为什么typeof []不返回array

Is this just a 'standard' that is followed or is there a valid reason? 这只是一个遵循的“标准”还是有正当理由?

Because that's what the spec says. 因为这就是规范所说的。

typeof returns primitive types only; typeof仅返回原始类型; all regular objects are reported as "object" . 所有常规对象都报告为"object"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM