2012-01-10 65 views
3

-a功能下面是谷歌開發者控制檯爲什麼typeof運算對象,字符串,數字...在Javascript

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.constructor不是一個函數Object()?

謝謝 的MIro

回答

7

標識符ObjectString等不是「類名」,你可能會在其他語言中都看到了。它們也不是實例的特定類型。

Object本身是構造函數對於「對象」,即對函數的引用。

使事情進一步複雜化,Javascript函數也是可能具有屬性的對象。這些屬性通常用於將方法添加到對象。

相關問題