lexical for-in/for-of loose end

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Feb 1 12:16:10 PST 2012


Another loose end.

With the addition of for-of, for-in reverts back to always iterating over the property keys of an object as it does not support the generalized iteration protocols.  An implication of this is that using a de-structuring pattern as the iteration variable has very limited utility:

for (let [c] in obj) print(c);  //print the first character of each of obj's enumerable property names

for (const {length:len}  in obj) print(len);  print the length of each of obj's enumerable property names

Given this lack of utility, why should we allow de-structuring in this context?

Eliminating it arguably increases language complexity by introducing in a bit more grammar irregularity.  On the other hand, eliminating useless functionality can be seen as as simplification.

I'm leaning towards banning destructing in for-in.

Allen




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120201/3d6e629a/attachment.html>


More information about the es-discuss mailing list