简体   繁体   English

为什么typeof Object,String,Number ... -a函数在Javascript中

[英]Why is typeof Object,String,Number… -a function in Javascript

Below is excerpt from Google Developer Console 以下摘自Google Developer Console

typeof Object  // type of Object is function (most confusing part).
"function"      //Same fot all build-in types

Object.constructor 
function Function(){[native code]}// Why not function Object()?

Object.hasOwnProperty("create")  // Here, it is Object since it has property,not typeof      
"true"                              function


dir(Object) // Again, Object is object,it has property (method)
function Object() { [native code] }

Why typeof Object is not Object ? 为什么typeof Object不是Object? And why Object.constructor is not a function Object() ? 为什么Object.constructor不是函数Object()?

Thank you MIro 谢谢MIro

The identifiers Object , String , etc are not "class names" as you might have seen in other languages. 标识符ObjectString等不是您在其他语言中看到的“类名”。 Nor are they instances of the specific type. 它们也不是特定类型的实例

Object on its own is the constructor for an "Object", ie a reference to a function. Object本身就是“对象”的构造函数 ,即对函数的引用。

To further complicate matters, Javascript functions are also objects, which may have properties. 更复杂的是,Javascript函数也是对象,它们可能具有属性。 Those properties are often used to add methods to objects. 这些属性通常用于向对象添加方法

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

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