set.add and set.delete return values

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Feb 13 23:59:58 PST 2012


typo in my line too

add(key) { const map = private(this).map; return !map.has(key) &&
!map.set(key, true); }



...

On Tue, Feb 14, 2012 at 8:58 AM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> there is a typo in the Set delete definition, return
> private(this).delete(key) should be return private(this).map.delete(key);
>
> AFAIK add does behave indeed like that and it's in my shim indeed, add
> returns true if added, false otherwise.
>
> I would change that code into
>
> add(key) { const map = private(this).map; return !(map.has(key) && map.set(key, true)); }
>
>
> br
>
>
> On Tue, Feb 14, 2012 at 6:28 AM, Peter Michaux <petermichaux at gmail.com>wrote:
>
>> The return value set.delete tells the caller if the set was modified
>> or not. It would be useful if the return value of set.add did the
>> same. For example, this way a model in MVC could efficiently know if
>> and notify observers that a real change to the set actually happened.
>>
>> http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
>>
>> Peter
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120214/b6424890/attachment.html>


More information about the es-discuss mailing list