Iterate over String.prototype

I know that a for in loop can help iterate over the properties of objects, prototypes, and collections.

The thing is, I need to String.prototype over String.prototype , and although console.log(String.prototype) displays the full prototype when I do

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

in order to display the name of the elements in the prototype, it does not display anything, as if it were empty.

JavaScript utilities hide basic prototype methods, or am I doing something wrong?

+4
source share
3 answers

The specification states:

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

Table 7 - Default attribute values

...

[[Enumerable]] false

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

+4
source

Like others, all properties in String.prototype are not enumerable. For a list of all properties, including non-enumerable ones, use Object.getOwnPropertyNames () (only for new browsers)

+3
source

Native methods are not visible using the iteration for(prop in obj) .

You can find properties when scrolling an embedded object. In this case, the page expanded the prototype using a special method. Thus, Framework (e.g. jQuery) often modify inline objects.

+1
source

All Articles