Would something like :
obj[prop] ||= NewProp
be useful?
--
*'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@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
Le 12/06/2012 15:27, Hemanth H.M a écrit :
Would something like :
|obj[prop] ||= NewProp|
be useful?
ahah, I asked the same question very recently [1]. Answer by Brendan
Eich [2].
I definitely agree that default arguments are a decent alternative. I
can't recall examples where it wouldn't be
On Tue, Jun 12, 2012 at 10:33 AM, David Bruant bruan...@gmail.com wrote:
Le 12/06/2012 15:27, Hemanth H.M a écrit :
Would something like :
obj[prop] ||= NewProp
be useful?
There is currently a strawman proposal for the Default Operator, which
can be found here:
Kool, well was looking into use caseswell my first frustration was [1]
I'm new to this, how does one write proposals? Is it a wiki?
[1] https://twitter.com/GNUmanth/status/208555914733682690
On Tue, Jun 12, 2012 at 8:36 PM, Rick Waldron waldron.r...@gmail.comwrote:
On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.comwrote:
I use ||= very regularly in ruby and coffeescript, both of which have
default arguments.
I definitely agree that default arguments are a decent alternative. I
can't recall examples where it wouldn't be enough. Do you
+1
I desperately want this in the language.
AJ ONeal
On Tue, Jun 12, 2012 at 11:14 AM, Rick Waldron waldron.r...@gmail.comwrote:
On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.comwrote:
I use ||= very regularly in ruby and coffeescript, both of which have
default
Rick Waldron wrote:
On Tue, Jun 12, 2012 at 11:45 AM, Ryan Florence rpflore...@gmail.com
mailto:rpflore...@gmail.com wrote:
I use ||= very regularly in ruby and coffeescript, both of which
have default arguments.
I don't see Ryan's mail.
First, as we've discussed in the past, ||=
This breaks from JS's C-inspired assignment operators, but perhaps we can
live with it.
FWIW -- I was confused when I first read ||=, I thought it was supposed to
be some kind of Boolean-coercing variant on |=. Now I see that it is more
like ?= from GNU make.
What do you think of GCC's ?:
Wes Garland wrote:
This breaks from JS's C-inspired assignment operators, but perhaps
we can live with it.
FWIW -- I was confused when I first read ||=, I thought it was
supposed to be some kind of Boolean-coercing variant on |=. Now I see
that it is more like ?= from GNU make.
We could
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
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).
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
On Tue, Jun 12, 2012 at 2:31 PM, Tom Ellis tellis...@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.
- Russ
Tom
On 12 Jun 2012, at 19:04, Brendan
Russell Leggett wrote:
On Tue, Jun 12, 2012 at 2:31 PM, Tom Ellis tellis...@gmail.com
mailto:tellis...@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,
Brendan Eich wrote:
LeftHandSideExpression ?= AssignmentExpression
are roughly
Let lref = evaluate A.
Let lval = GetValue(lref).
Let rref = evaluate B.
Of course, A should be LeftHandSideExpression and B should be
AssignmentExpression.
This is pretty simple. We could even grant an
Updated. Sorry, no ||| instead of ??. Instead, inspired by Wes's GCC
reminder, I kept the ?? operator but re-spelled it as ?: and made ??= be
spelled ?=.
http://wiki.ecmascript.org/doku.php?id=strawman:default_operator
The semantics match only undefined. APIs use null as no-object and do
not
On Tue, Jun 12, 2012 at 3:09 PM, Brendan Eich bren...@mozilla.org wrote:
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
On Jun 12, 2012, at 3:26 PM, John Tamplin wrote:
On Tue, Jun 12, 2012 at 3:09 PM, Brendan Eich bren...@mozilla.org wrote:
And (to be clear) the semantics for
LeftHandSideExpression ?= AssignmentExpression
are roughly
Let lref = evaluate A.
Let lval = GetValue(lref).
Let rref =
Heh, I did write *roughly* :-P.
Let lref = evaluate LeftHandSideExpression.
Let lval = GetValue(lref).
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
•
Ok, that (cited below) was wrong too.
This should be right:
http://wiki.ecmascript.org/doku.php?id=strawman:default_operator#semantics
Comments welcome. Thanks again, I needed some caffeine!
/be
Brendan Eich wrote:
Heh, I did write *roughly* :-P.
Let lref = evaluate
On Jun 12, 2012, at 11:02 AM, Brendan Eich wrote:
It's possible ?? or however we spell it isn't worth adding, while ?= is. The
conditional assignment to default or normalize is the prime use-case.
I'm skeptical. You don't foresee
f(obj.x ?? defVal)
happening a lot? I do.
Dave
, 2012 at 11:45 AM
Subject: Re: ||= is much needed?
To: Rick Waldron waldron.r...@gmail.com
Cc: David Bruant bruan...@gmail.com, es-discuss@mozilla.org
I use ||= very regularly in ruby and coffeescript, both of which have
default arguments.
I definitely agree that default arguments are a decent
On Jun 12, 2012, at 5:57 PM, David Herman dher...@mozilla.com wrote:
On Jun 12, 2012, at 11:02 AM, Brendan Eich wrote:
It's possible ?? or however we spell it isn't worth adding, while ?= is. The
conditional assignment to default or normalize is the prime use-case.
I'm skeptical. You
Ryan Florence wrote:
But if we're adding ?= because we're adding ?: maybe its okay to add
||= while we're at it? That said, I would hate to see ?= get derailed
because ||= is dumb.
Dumb is too strong. How about YAGNI? Every use-case of || I've seen in
JS (almost all with the result of || the
On Jun 12, 2012, at 7:41 PM, Ryan Florence wrote:
I'm skeptical. You don't foresee
f(obj.x ?? defVal)
happening a lot? I do.
I can't speak for the world but I've never seen anybody do f(val ||= defVal)
in Ruby or CoffeeScript.
But I'm not talking about ||=. I'm talking about the
People don't default on the caller side (at the callsite) much, in my
experience. Dave may be seeing other sources, but it's extremely rare in
my experience to see
foo(arg1 || callers_idea_of_default_arg1_value);
whereas we all see
function foo(a, b, c) {
a = a || default_a;
b.x
I think it’d be handy when you are taking apart objects (e.g. JSON data).
However, you do have the option of merging in default values (e.g. via
http://documentcloud.github.com/underscore/#defaults ).
On Jun 13, 2012, at 7:52 , Brendan Eich wrote:
People don't default on the caller side (at
101 - 126 of 126 matches
Mail list logo