谢谢。
参考了:
http://stackoverflow.com/questions/15919717/print-the-javascript-string-object-properties-and-methods (string的所有properties all non-
enumerable) 所以,for..in不能打印出String的所有属性。
// nothing displayed because of all properties are non-enumerable
for (var x in String) {
console.log(x);
}
// print increased indices of char arrays, why !!! [1] here is my question
for (var x in new String("hello")) {
console.log(x);
}
还有一个问题:为何[1]出打印出0, 1, 2, 3, 4
是因为上下文的缘故,new String("hello")被解释为数组? (右值解释成数组)
【 在 XeCycle (据说是小 X) 的大作中提到: 】
: literal strings are primitives (typeof str === "string")
: new String() creates objects (typeof str === "object" && str instanceof
String)
: for...in iterates over all enumerable properties
: ...................
--
FROM 125.120.155.*