![](/img/trans.png)
[英]Why does typeof Array returns “function” and typeof [array variable] returns an “Object”?
[英]When typeof is run on a function, it returns “function” as the type. Why doesn't it return “object”?
Javascript 中的 function 是 object。
在 function 上運行 typeof 時,為什么它返回值“函數”而不是“對象”?
var objLit = {} console.log(typeof objLit); // "object" function hello() { console.log("hello world"); } console.log(typeof hello); // "function"
因為這就是規范所說的。 盡管所有函數都是對象,但在 function 上使用typeof
時將返回'function'
而不是'object'
。 見表:
Type of val Result: Object (does not implement [[Call]]) "object" Object (implements [[Call]]) "function"
(函數有內部方法 [[Call]];非函數沒有。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.