Logical Assignment Operators

Brad Fults bfults at gmail.com
Tue Oct 9 18:33:55 PDT 2007


Hi,

As far as I can tell [1] there have never been logical assignment
operators (AND, OR) in ES and I can't access the spec on the wiki [2]
anymore, so I don't know if they're in the spec. I don't see anything
in the proposals section, so here's a proposal.

Add two operators to ES:

    ||=
    &&=

The purpose should be obvious, as they mirror the pattern of all other
shortcut assignment operators and have existed in other languages for
a long time.

Example

    a ||= 0
    is the same as
    a = a || 0

Any insight into the issues surrounding this part of the language
would be appreciated.

Thanks.

[1] - http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Assignment_Operators
[2] - http://wiki.ecmascript.org/doku.php?id=spec:spec

-- 
Brad Fults



More information about the Es4-discuss mailing list