||= is much needed?

Brendan Eich brendan at mozilla.org
Tue Jun 12 12:09:47 PDT 2012


Russell Leggett wrote:
> On Tue, Jun 12, 2012 at 2:31 PM, Tom Ellis <tellishtc at gmail.com 
> <mailto:tellishtc at gmail.com>> wrote:
>
>     I like the sound of ?= too.
>
>     var a;
>
>     //later on
>
>     a ?= 15;
>
>     It goes with all the other operators that are out there too (!=,
>     =, ==, === etc).
>
>
> +1, useful and intuitive.

And (to be clear) the semantics for

LeftHandSideExpression ?= AssignmentExpression

are roughly

Let lref = evaluate A.
Let lval = GetValue(lref).
Let rref = evaluate B.
Let rval = GetValue(rref).
Throw a SyntaxError exception if the following conditions are all true:
• Type(lref) is Reference is true
• IsStrictReference(lref) is true
• Type(GetBase(lref)) is Environment Record
• GetReferencedName(lref) is either "eval" or "arguments"
If lval is undefined, call PutValue(lref, rval).

to assign the default value if and only if the left-hand side's current 
value is undefined.

/be
>
> - Russ
>
>
>     Tom
>
>     On 12 Jun 2012, at 19:04, Brendan Eich wrote:
>
>     > Brendan Eich wrote:
>     >> Is this (A ? B) ? C : D or A ? (B ? C) : D. We can disambiguate
>     in the formal grammar but readers may rebel.
>     >
>     > Or A ? (B ? C : D), of course.
>     >
>     > Just say no to lone ? as new operator. I'm warming up to ?= though!
>     >
>     > /be
>     > _______________________________________________
>     > es-discuss mailing list
>     > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>     > https://mail.mozilla.org/listinfo/es-discuss
>
>     _______________________________________________
>     es-discuss mailing list
>     es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>     https://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss


More information about the es-discuss mailing list