shorthand notation for attribute creation?

Andrea Giammarchi andrea.giammarchi at gmail.com
Sun Feb 9 12:29:23 PST 2014


Unless I misunderstood your idea, `||=` makes me naturally think about `+=`
so if

`i += n;` means `i = i + n`

then

`o.name ||= value` means `o.name = o.name || value`

and this would be, according with all these years in ES3, the least
surprising behavior which is **way different** from checking if `name` is
not defined.

Accordingly, I wonder ...

   1. what if `name` was inherited with a non _falsy_ value ?
   2. what if `name` was defined as `undefined` ?
   3. should that silently fail if `name` was already defined ?

Cheers





On Sun, Feb 9, 2014 at 2:17 AM, Hemanth H.M <hemanth.hm at gmail.com> wrote:

> Something like `var foo = {}; foo.bar ||= 3` would be very useful.
>
> But not sure how something like `obj['name']['maxlength']` be reduced to
> shorthand check if 'name' is not defined.
>
>
>
> --
> *'I am what I am because of who we all are'*
> h3manth.com <http://www.h3manth.com>
> *-- Hemanth HM *
>
> _______________________________________________
> 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/20140209/aae97dfd/attachment.html>


More information about the es-discuss mailing list