简体   繁体   中英

why Array.prototype only output [] in console?

String.prototype

String {}

Object.prototype

Object {}  

Boolean.prototype

Boolean {}

but Array.prototype outputs [] , why not Array [] or something else? What happened?

I looked into the ECMA specs and V8 source code, but I couldn't get a concrete answer.

According to the ECMA-262 spec , every object must have algorithms for all of the essential internal methods, however, all objects do not necessarily use the same algorithms for those methods which means the output will be implementation specific at least in the case of [[GetPrototypeOf]] .

Hence, if you try the same in different browsers, you'll notice that the output is slightly different in each.

Internet Explorer 11:

Array.prototype
[object Array]  []

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

Object.prototype
[object Object]  {}

Boolean.prototype
[object Boolean]  {}

Firefox:

Array.prototype
[object Array]

String.prototype
[object String]

Object.prototype
[object Object]

Boolean.prototype
[object Boolean]

Chrome and Opera:

Array.prototype
[]

String.prototype
String {}

Object.prototype
Object {}

Boolean.prototype
Boolean {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM