迭代String.prototype [英] Iterate over String.prototype

查看:72
本文介绍了迭代String.prototype的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道循环中的可以帮助迭代对象,原型和集合的属性。

I am aware that the for in loop can help iterate through properties of objects, prototypes and collections.

事实是,我需要迭代 String.prototype ,尽管 console.log(String.prototype)显示完整的原型,当我执行

The fact is, I need to iterate over String.prototype, and though console.log(String.prototype) displays the complete prototype, when I do

for (var prop in String.prototype) {
    console.log(prop);
}

显示原型中元素的名称,它不显示任何内容,如如果它是空的。

to display the name of the elements in the prototype, it displays nothing, as if it were empty.

JavaScript引擎是否隐藏了基本的原型方法,或者我做错了什么?

Do the JavaScript engines hide the basic prototypes methods, or am I doing something wrong?

推荐答案

规范说:


如果未明确指定属性的值对于命名属性的规范,使用表7中定义的默认值。

If the value of an attribute is not explicitly specified by this specification for a named property, the default value defined in Table 7 is used.

表7 - 默认属性值

Table 7 — Default Attribute Values

...

[[Enumerable]] false

[[Enumerable]] false

所以它不是可枚举的(与所有内置属性一样)。

So it is not enumerable (as with all built-in properties).

这篇关于迭代String.prototype的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆