Why not NodeList#forEach :\?

David Bruant bruant.d at gmail.com
Mon Jun 11 06:18:26 PDT 2012


Le 11/06/2012 15:13, Hemanth H.M a écrit :
> Uber kool! Thanks a ton David!
> |npm install es6-shim # wow :) Shall blog about this!
>
>
> |
> Well, Map() and Set() is already there is FF13, it's 
> an experimental API right? Experimental means it can be chucked off or 
> it shall be modified drastically ?  ( More Java like APIs :\ )
>
>
> Well {} behaved liked map and well for sets we can use 
> [].sort.filter(function(v,i,o){return v!==o[i-1];}
The major use case for Maps and Sets (as far as i'm concerned) is the 
ability to use objects as keys. Having built-in implementation of these 
potentially enable O(1)-ish lookups (which is impossible to implement in 
JavaScript).
As to Maps and {} being equivalent, that's true expect when it's not, 
like when you want to use pseudo properties like __proto__ or 
__noSuchMethod__ as keys. Some folks tried to use objects as maps and 
got burned [1]. See Caja's StringMap [2] for a workaround when you only 
need strings as keys.

David

[1] http://productforums.google.com/forum/#!topic/docs/0hQWeOvCcHU
[2] 
http://code.google.com/p/google-caja/source/browse/trunk/src/com/google/caja/ses/StringMap.js
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120611/6bb1231b/attachment.html>


More information about the es-discuss mailing list