为什么typeof Object、String、Number-Javascript中的一个函数

Why is typeof Object,String,Number... -a function in Javascript

本文关键字:一个 函数 Object typeof String Number-Javascript 为什么      更新时间:2023-09-26

以下是谷歌开发者控制台的摘录

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] }

为什么Object的类型不是Object?为什么Object.constructor不是函数Object()?

谢谢MIro

标识符ObjectString等不是您在其他语言中可能看到的"类名"。它们也不是特定类型的实例

Object本身就是"Object"的构造函数,即对函数的引用。

更为复杂的是,Javascript函数也是对象,它们可能具有属性。这些属性通常用于将方法添加到对象中。