简体   繁体   English

为什么不将“function”视为javascript中的数据类型?

[英]why isn't “function” considered a datatype in javascript?

The datatypes listed in MSDN for javascript are Number, String, Boolean, Object, Array, Null, Undefined. MSDN中为javascript列出的数据类型是Number,String,Boolean,Object,Array,Null,Undefined。 However, when you do typeof function , its type is function. 但是,当您执行typeof function ,其类型是函数。

Why is this the case, and what's the definition of datatype? 为什么会这样,数据类型的定义是什么?

Functions are just Objects in JavaScript. 函数只是JavaScript中的对象。 But the difference lies in an internal property called [[Call]] that differentiates them from normal Objects. 但不同之处在于一个名为[[Call]]的内部属性,它将它们与普通对象区分开来。 When typeof is used against an Object, and if it finds the [[Call]] property, then it returns the String "function". typeof用于对象时,如果它找到[[Call]]属性,则返回String“function”。

This behavior can be found in the ECMA Specification for typeof . 这种行为可以在发现ECMA规范typeof

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

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