[英]Why is typeof Object,String,Number… -a function in Javascript
以下摘自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] }
為什么typeof Object不是Object? 為什么Object.constructor不是函數Object()?
謝謝MIro
標識符Object
, String
等不是您在其他語言中看到的“類名”。 它們也不是特定類型的實例 。
Object
本身就是“對象”的構造函數 ,即對函數的引用。
更復雜的是,Javascript函數也是對象,它們可能具有屬性。 這些屬性通常用於向對象添加方法 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.