Default value argument for Map/WeakMap.prototype.get()

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Nov 28 15:21:23 PST 2012


right, I have explained my concern better in my latest reply.

br


On Wed, Nov 28, 2012 at 2:41 PM, Tab Atkins Jr. <jackalmage at gmail.com>wrote:

> On Wed, Nov 28, 2012 at 1:16 PM, Andrea Giammarchi
> <andrea.giammarchi at gmail.com> wrote:
> > has is another story and your functions will fail.
> > I have provided already this example which is perfectly valid:
> >
> > var m = new Map;
> > m.set(m, undefined);
> > m.has(m); // true
>
> ...what?  Why would my functions fail?  Assuming you use them instead
> of the built-in map functions, they work just fine.
>
> > all you need in JS, which is not Python, is the ||
> >
> > m.get(key) || defaultValue
> >
> > which is the most common case, as you wrote, for maps.
>
> This fails if the value is 0, null, false, undefined, or any other falsey
> value.
>
> > I strongly doubt you gonna store false, empty strings, or null as values,
> > right?
>
> It's completely reasonable to store those things, and I have done
> exactly that when using dictionaries in languages like Python and
> Lisp.
>
> > It's also funny I have already implemented that and it is not me pushing
> > back so ... I actually don't get anything you said or what you think I
> wrote
>
> You said (paraphrasing, obviously) "there's no need to add this
> feature, because authors can just add a one-line function that
> accomplishes it".  I was just responding that this is a bad argument;
> while the ease of coding it yourself is a relevant factor, it's not
> the only one, as one should also consider how often it'll be used.
>
> ~TJ
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121128/e99bd0aa/attachment.html>


More information about the es-discuss mailing list