Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterate over String.prototype

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

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.

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

like image 449
xavier.cambar Avatar asked Jan 18 '23 12:01

xavier.cambar


1 Answers

The specification says:

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.

Table 7 — Default Attribute Values

...

[[Enumerable]] false

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

like image 129
pimvdb Avatar answered Jan 27 '23 19:01

pimvdb