Null iterable in for-of?
jwalden+es at MIT.EDU
Thu Jun 12 15:12:03 PDT 2014
On 06/12/2014 03:05 PM, Allen Wirfs-Brock wrote:
> I believe this behavior for for-in was added in ES5. My recollection was that Doug Crockford pushed for it. I don't recall if it was because it matched web reality or simply because he thought it was a good idea.
It was added for web compatibility, to track what was originally a SpiderMonkey implementation bug, I believe.
> I agree that treating null/undefined as an empty collection has a smell. However, in this case my I agree with who ever it was who reported this. that consistancy between for-in and for-of is what we should have for this condition.
The spec regarding for-of read the other way, before the latest update, precisely because the web compatibility argument was poor justification for for-in working that way, and for-of was an opportunity to do the right thing. (SpiderMonkey implements the throw-on-null/undefined behavior now.) This was a deliberate inconsistency. I would have argued/responded in that bug with WONTFIX.
More information about the es-discuss