简体   繁体   English

为什么Array.prototype只在控制台中输出[]?

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

String.prototype String.prototype

String {}

Object.prototype Object.prototype中

Object {}  

Boolean.prototype Boolean.prototype

Boolean {}

but Array.prototype outputs [] , why not Array [] or something else? Array.prototype输出[] ,为什么不是Array []或其他东西? What happened? 发生了什么?

I looked into the ECMA specs and V8 source code, but I couldn't get a concrete answer. 我查看了ECMA规范和V8源代码,但我无法得到具体答案。

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]] . 根据ECMA-262规范 ,每个对象必须具有所有基本内部方法的算法,但是,所有对象不一定对这些方法使用相同的算法,这意味着输出将是特定于实现的,至少在[ [GetPrototypeOf]]

Hence, if you try the same in different browsers, you'll notice that the output is slightly different in each. 因此,如果您在不同的浏览器中尝试相同的操作,您会注意到每个浏览器的输出略有不同。

Internet Explorer 11: 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: 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