classes and enumerability

Brendan Eich brendan at mozilla.org
Wed Dec 24 16:56:06 PST 2014


Sorry, you can't use small-world reasoning about programming in the 
large, especially with JS on the web. for-in proliferated, before 
hasOwnProperty appeared in ES3. Even after, the burden was high enough, 
per that study Allen cited 
(http://munawarhafiz.com/research/jssurvey/GHB14-JSUsedParts.pdf). 
for-in ain't going away.

If you are saying we should make class prototype methods non-enumerable 
in ES6, I agree. If you're saying it won't matter that they remain as 
drafted, enumerable, because everyone will stop using for-in. I don't 
buy it. If you are suggesting that for-in-based code won't be run on 
class prototypes, perhaps -- but that's a gamble.

/be

Gary Guo wrote:
> Actually I believe that there will not be many cases that we need to 
> use for-in loop in ES6. In most cases enumerate through properties in 
> the prototype chain is not preferable. for-of Object.keys should be 
> enough for enumeration with own properties. If my assumption is 
> correct, since we are less likely to use legacy ways, we will be more 
> able to make a change. 


More information about the es-discuss mailing list