String.prototype
是只读属性 不能通过接口枚举出来
for (var name in window)                    //为什么利用for(variable in Object)的语法枚举不到charAt属性 

document.write(name+" <BR/>"); 

解决方案 »

  1.   

    <html> 
    <head> 
    <title>JS </title> 
    </head> 
    <body> 
    <script type="text/javascript"> 
    document.write(typeof(String.prototype)+" <BR/>");    //显然prototype是对象类型 
    document.write("charAt" in String.prototype);        //显然charAt是String.prototype对象的一个原生属性 
    alert(String.propertyIsEnumerable("prototype")); //false 不能被枚举
    for (var name in String.prototype)                    //为什么利用for(variable in Object)的语法枚举不到charAt属性 

    document.write(name+" <BR/>"); 

    </script> 
    </body> 
    </html>
      

  2.   


    只读属性不是从某个对象prototype上面继承的属性么 ? String.prototype.hasOwnProperty("charAt")返回的是真啊?按理说应该能枚举出来啊为什么
    String.prototype.propertyIsEnumerable("charAt")又返回false呢?
      

  3.   

    终于找到正解了。JS里面无所谓只读属性吧, 真正的只读属性就是function CustomObject (property) {
         this.property = property;
    }CustomObject.prototype.readOnlyProperty = "constant";var obj = new CustomObject("variable");对于obj而言, readOnlyProperty就是只读属性, 因为这个属性是来自于prototype的, 每当obj.readOnlyProperty = "value"的时候相当于自己另外创建了一个。我看JS权威指南上面写到:对于built-in类型, 其属性不可枚举。这个相当于一个例外情况!所以不是因为只读不只读属性的原因。~