[英]How does the String constructor function in Javascript return an Object without a key?
When I do new String("hello")
in my console I get the following result: 当我在控制台中执行
new String("hello")
,得到以下结果:
String {"hello", length: 5}
The first value in the String Object that was returned doesn't have a key. 返回的String对象中的第一个值没有键。
Since objects are associative/hash arrays ie defined and created with keys and values how is the String constructor returning an object with a value without key? 由于对象是关联/哈希数组,即使用键和值定义和创建,因此String构造函数如何返回不带键的值的对象?
It doesn't. 没有。
You're just misinterpreting the console's visualisation of a string object and assuming it is expressing it in the form of object literal syntax. 您只是误解了控制台对字符串对象的可视化,并假定它以对象文字语法的形式表示它。 If it would, you would see:
如果可以,您将看到:
{ 0: "h", 1: "e", 2: "l", 3: "l", 4: "o", length: 5, __proto__: String }
But thats certainly quite unreadable, so they probably changed the way of visualizing to make it easier to read. 但这肯定是不可读的,因此他们可能改变了可视化方式,以使其更易于阅读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.