Aurora VS Canary Map and Set

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Jun 14 03:00:00 PDT 2012


Hi again,
   here few inconsistencies I have found with latest version, for Mac, of
these two dev/channel browsers.

Map#set(key, value)
  Aurora: Map#set() returns undefined in any case. After, if value is
undefined/void 0, Map#has(key) will return true and Map#get(key) will
return undefined/void 0
  Canary: Map#set() returns the set value in any case. After, if value is
undefined/void 0, Map#has(key) will return false. The key will be removed
indeed so the get(key) will return undefined.

My Take:
  returning the value with Map#set may become handier than returning always
undefined, in a JavaScript like code style.
  deleting implicitly the key makes no sense at all. Map has so much focus
on edge cases such NaN and +0 VS -0 but an explicit value as undefined is
cannot be assigned as desired value BUT it can be used as key ?!?? Implicit
key removal goes against Map#delete(key) logic too since this method
returns true or false accordingly if the key was there or not.

As Summary

*anything value Map#set(anything key, anything value) looks the most
concrete/meaningful signature without implicit Map#delete(key) calls ...
please clarify if what I am saying makes sense and if both Aurora and
Canary will follow this behavior, thanks.


Set#delete(keyAsValue)
  Aurora: consistent behavior with Map#delete(key) ... the returned value
is a boolean, true or false if the key was there
  Canary: inconsistent behavior with Map#delete(key) ... Set#delete(
keyAsValue) returns undefined and I really do not understand why this is
happening. My tests fails with surprise here while these where green before
... bad choice, imho, I'd like to understand why is that.

Set#add(keyAsValue)
  both Aurora and Canary returns undefined here and I find this a bit
inconsistent too. I see Set#add as a simplified Map#set where keyAsValue
could be returned.
If your argument is that Set#add(keyAsValue) has different purpose than
Map#set I wonder why the behavior is not consistent with Map#delete(key)
where at least, Set#add(keyAsValue) could return true or false accordingly
if the keyAsValue was there or not.

if (Set#add(generic)) {
  // first time generic has been set
} else {
  // generic was there already
}

My Take:
  while the returning boolean could be considered superfluous, since it
could be implemented in Set#delete(generic) or simply passing through the
Set#has(generic) check, returning the added generic value would be more
than helpful for many common tasks.

mySingleSet.add(myGenericObject).methodCallOnAdd(/*args*/);

Thanks for any sort of clarification.

Best Regards,
    Andrea Giammarchi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120614/23128881/attachment.html>


More information about the es-discuss mailing list