簡體   English   中英

為什么Array.prototype只在控制台中輸出[]?

[英]why Array.prototype only output [] in console?

String.prototype

String {}

Object.prototype中

Object {}  

Boolean.prototype

Boolean {}

Array.prototype輸出[] ,為什么不是Array []或其他東西? 發生了什么?

我查看了ECMA規范和V8源代碼,但我無法得到具體答案。

根據ECMA-262規范 ,每個對象必須具有所有基本內部方法的算法,但是,所有對象不一定對這些方法使用相同的算法,這意味着輸出將是特定於實現的,至少在[ [GetPrototypeOf]]

因此,如果您在不同的瀏覽器中嘗試相同的操作,您會注意到每個瀏覽器的輸出略有不同。

Internet Explorer 11:

Array.prototype
[object Array]  []

String.prototype
[object String]  {length:0}

Object.prototype
[object Object]  {}

Boolean.prototype
[object Boolean]  {}

火狐:

Array.prototype
[object Array]

String.prototype
[object String]

Object.prototype
[object Object]

Boolean.prototype
[object Boolean]

Chrome和Opera:

Array.prototype
[]

String.prototype
String {}

Object.prototype
Object {}

Boolean.prototype
Boolean {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM