shorthand notation for attribute creation?

Hemanth H.M hemanth.hm at gmail.com
Sun Feb 9 22:52:27 PST 2014


I had this hunch that it was out there somewhere...hmm thank you guys!

I do agree default parameters, and default destructuring values is the way
to go.




On Mon, Feb 10, 2014 at 6:08 AM, Brendan Eich <brendan at mozilla.com> wrote:

> Good memory. This is all at esdiscuss.org in the meeting notes, but I
> can't google for ||= to save my life, even in Verbatim mode. Anyone?
>
> Of course the original proposal is still in strawman stage on the wiki:
>
> http://wiki.ecmascript.org/doku.php?id=strawman:default_operator
>
> /be
>
>  Domenic Denicola <mailto:domenic at domenicdenicola.com>
>> February 9, 2014 at 12:49 PM
>>
>> There was very active discussion, probably around 1.5 years ago, about
>> `||=` vs. a proposed `?=` (where `x ?= y` ≈ `x = x !== undefined ? x : y`).
>>
>> From what I recall some of the major points of discussion were:
>>
>> - Should `?=` use `undefined` as its sentinel, or work with either `null`
>> or `undefined`? (This was before the behavior for default parameters was
>> decided.)
>> - Would adding `||=` be an attractive nuisance, when people "should" be
>> using `?=` instead?
>> - Given the existence of default parameters, and default destructuring
>> values, are either of these even necessary?
>>
>> The last point, I think, was what killed both `?=` and `||=`. They become
>> much less necessary when you can write things like
>>
>> ```js
>> function f(foo = true, { bar = 5, baz = "ten" } = {}) {
>> console.log(foo, bar, baz);
>> }
>> ```
>>
>> From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of
>> Andrea Giammarchi
>> Sent: Sunday, February 9, 2014 15:29
>> To: Hemanth H.M
>> Cc: es-discuss
>> Subject: Re: shorthand notation for attribute creation?
>>
>> 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.
>>
>>
>>
>>
>> Andrea Giammarchi <mailto:andrea.giammarchi at gmail.com>
>> February 9, 2014 at 12:29 PM
>>
>> Unless I misunderstood your idea, `||=` makes me naturally think about
>> `+=` so if
>>
>> `i += n;` means `i = i + n`
>>
>> then
>>
>> `o.name <http://o.name> ||= value` means `o.name <http://o.name> = o.name<
>> http://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
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>


-- 
*'I am what I am because of who we all are'*
h3manth.com <http://www.h3manth.com>
*-- Hemanth HM *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140210/1f0e3768/attachment.html>


More information about the es-discuss mailing list