On Apr 13, 2012, at 3:42 PM, Sam Tobin-Hochstadt wrote:
On Fri, Apr 13, 2012 at 5:42 PM, Brendan Eich bren...@mozilla.org wrote:
Sam has similar testimony from Racket (neé PLT-Scheme).
Very much so -- I've encountered places where Racket's semantics for
keyword arguments (which is similar
What about functions that take two or more independent optional arguments,
where sometimes you want to omit the first argument while providing the second?
For example, in the ECMAScript Internationalization API:
Intl.Collator = function(localeList, options) { ... }
currently fills in
This is covered on the wiki too.
http://wiki.ecmascript.org/doku.php?id=harmony:parameter_default_values
On Thu, Apr 12, 2012 at 20:38, Russell Leggett
russell.legg...@gmail.com wrote:
The examples cited are arguably cases where the built-in behaviour is
unintuitive to many JavaScript
Fwiw, arguments.length is currently the _only_ way of properly
detecting the correct number of explicit variables of _any_ type. I
would hate for that behavior to change in the case of explicitly
passing on undefined.
Default values of course do need to be set in the arguments array so
it's
If you really need to know how many arguments were passed just use rest
parameters.
We should definitely not add more API to the arguments object.
On Apr 13, 2012 1:34 AM, Peter van der Zee e...@qfox.nl wrote:
Fwiw, arguments.length is currently the _only_ way of properly
detecting the correct
On Apr 12, 2012, at 7:31 PM, Luke Hoban wrote:
...
This is a good way of explaining the proposed semantics, but...
But I see why somebody calling a function defined as function(a={ }){...}
explicitly as f(undefined) would expect to trigger the default value
initializer.
Right.
On Fri, Apr 13, 2012 at 12:26 PM, Allen Wirfs-Brock
al...@wirfs-brock.comwrote:
On Apr 12, 2012, at 7:31 PM, Luke Hoban wrote:
...
This is a good way of explaining the proposed semantics, but...
But I see why somebody calling a function defined as function(a={ }){...}
explicitly as
On Apr 12, 2012, at 8:38 PM, Russell Leggett wrote:
At first the answer to this didn't really matter to me, because how often
does someone pass undefined to a function like foo(undefined). I know I
don't, though I'm sure it happens occasionally. Then I thought about it and
realized
I'd write it:
function fadeToggle(...args){
if(visible){
fadeOut(...args);
}else{
fadeIn(...args);
}
}
If you don't care about the the actual argument values are just passing
them on that's how you should do it.
Ok,
On Apr 12, 2012, at 11:25 PM, Norbert Lindenberg wrote:
What about functions that take two or more independent optional arguments,
where sometimes you want to omit the first argument while providing the
second?
arguably, this is where you should be using an options argument rather than
Allen Wirfs-Brock wrote:
On Apr 12, 2012, at 11:25 PM, Norbert Lindenberg wrote:
What about functions that take two or more independent optional arguments,
where sometimes you want to omit the first argument while providing the second?
arguably, this is where you should be using an
It’s an interesting case of “traditional lenient style” versus “new, more
strict style”. Both approaches have merit (pro leniency: familiarity,
compatibility). With arity checking, a first step towards the latter style has
been made, I think it makes sense to continue in that direction.
On Apr
On Apr 13, 2012, at 10:10 AM, Brendan Eich wrote:
Allen Wirfs-Brock wrote:
On Apr 12, 2012, at 11:25 PM, Norbert Lindenberg wrote:
What about functions that take two or more independent optional
arguments, where sometimes you want to omit the first argument while
providing the
On Apr 13, 2012, at 10:53 AM, Allen Wirfs-Brock wrote:
On Apr 13, 2012, at 10:10 AM, Brendan Eich wrote:
In general, delegation (depth D) plus optionality (degree N paramters) makes
an (2N)^D worst-case combinatorial explosion.
This is IMHO a strong argument for a sentinel in-language to
On Apr 13, 2012, at 9:38 AM, Russell Leggett wrote:
Yes, but as I said, and Erik pointed out is in the wiki, it is a lot more
likely that someone would pass f(foo) or f(obj.foo) where foo might be
undefined.
Bingo.
Expecting undefined as a possible valid argument (as opposed to a missing
What happens if i have:
function foo(a=1, b=2) { log(a, b, arguments.length); }
foo();
foo(undefined);
foo(3);
foo(undefined, undefined);
foo(undefined, 3);
foo(3, undefined);
Default values are for when arguments are not passed, it does not make logical
sense to say that they're the value
Making default values overridden by undefined makes them useless in a large
portion of cases, but not doing so makes arguments.length a liar and
invalidates other cases.
___
es-discuss mailing list
es-discuss@mozilla.org
On Apr 13, 2012, at 11:35 AM, Oliver Hunt wrote:
What happens if i have:
function foo(a=1, b=2) { log(a, b, arguments.length); }
foo();
1, 2, 2
foo(undefined);
1, 2, 1
foo(3);
3, 2, 1
foo(undefined, undefined);
1, 2, 2
foo(undefined, 3);
1, 3, 2
foo(3, undefined);
3, 2, 2
On Apr 13, 2012, at 11:46 AM, Allen Wirfs-Brock wrote:
On Apr 13, 2012, at 11:22 AM, David Herman wrote:
On Apr 13, 2012, at 10:53 AM, Allen Wirfs-Brock wrote:
That sentinel could simply be a empty argument position:
new Intl.Collator( , {usage: search});
That's not enough. It
On Apr 13, 2012, at 11:51 AM, Allen Wirfs-Brock wrote:
both sides of this debate seem a little smelly. But, Pretending that
undefined isn't a real value seems more smelly to me.
There's no need to think of it as pretending it's not a real value. Think of it
as saying that the undefined value
On Apr 13, 2012, at 11:48 AM, David Herman wrote:
On Apr 13, 2012, at 11:35 AM, Oliver Hunt wrote:
What happens if i have:
function foo(a=1, b=2) { log(a, b, arguments.length); }
foo();
1, 2, 2
Oops: 1, 2, 0
Dave
___
es-discuss mailing
On Apr 13, 2012, at 11:48 AM, David Herman dher...@mozilla.com wrote:
On Apr 13, 2012, at 11:35 AM, Oliver Hunt wrote:
What happens if i have:
function foo(a=1, b=2) { log(a, b, arguments.length); }
foo();
1, 2, 2
foo(undefined);
1, 2, 1
Uh what? I pass no arguments and
I'm sympathetic toward `undefined` as a sentinel for no value of the expected
type, whereas `null` means we have a value of the expected type, but that
value represents 'nothing.' Not sure if anyone else sees it that way, though,
and admittedly it's based on vague hand-wavey arguments.
David Herman wrote:
Think of it as saying that the undefined value is the idiomatic way in JS to represent
no value for the expected type. The smelly thing then is to create API's that
both use defaults and accept undefined as a valid input.
FTR, I'm on board with Arv, Dave, Russell, and
On Fri, Apr 13, 2012 at 3:05 PM, Oliver Hunt oli...@apple.com wrote:
On Apr 13, 2012, at 11:48 AM, David Herman dher...@mozilla.com wrote:
On Apr 13, 2012, at 11:35 AM, Oliver Hunt wrote:
What happens if i have:
function foo(a=1, b=2) { log(a, b, arguments.length); }
foo();
On Fri, Apr 13, 2012 at 12:00 PM, David Herman dher...@mozilla.com wrote:
On Apr 13, 2012, at 11:51 AM, Allen Wirfs-Brock wrote:
both sides of this debate seem a little smelly. But, Pretending that
undefined isn't a real value seems more smelly to me.
There's no need to think of it as
The story for JS is
undefined is no value
null is no object
It's definitely a just-so story, and some listeners want their money
back, but we're stuck with two. For defaulting, undefined is the only
choice of an in-language sentinel you can express. No one wants to add
yet another bottom
On Apr 13, 2012, at 12:05 PM, Oliver Hunt wrote:
On Apr 13, 2012, at 11:48 AM, David Herman dher...@mozilla.com wrote:
On Apr 13, 2012, at 11:35 AM, Oliver Hunt wrote:
foo(undefined);
1, 2, 1
Uh what? I pass no arguments and arguments.length is 2, and i pass one
argument and
Argh, I've caught Allen's dropped-negative disease:
Brendan Eich wrote:
I would be surprised if people wrote
function foo(a = default_a) {...}
and wanted
foo(undefined)
to bind default_a to a.
s/wanted/not want/
or else s/bind default_a to a/bind undefined to a/.
Will proofread
On Apr 13, 2012, at 12:16 PM, Brendan Eich wrote:
The story for JS is
undefined is no value
null is no object
Yet there are many places in the language where undefined is not the same as no
value. For example:
let mapped1 = [,,foo,,].map(v=v+1);
let mapped2
On Apr 13, 2012, at 12:16 PM, Brendan Eich wrote:
...
No one wants to add yet another bottom type and singleton value.
Permitting holes in argument lists, eg Intl.Collator( , {usage:search})
doesn't require either at the user language level or the specification level.
Whether a sentinel
Allen Wirfs-Brock wrote:
Making f() and f(undefined) mean the something (but only sometimes, you have to
look at the actual implementation of f to know for sure) seems to be add just
another internal inconsistency that makes it harder to form a general
conceptual model of the language.
This
On Fri, Apr 13, 2012 at 5:42 PM, Brendan Eich bren...@mozilla.org wrote:
Sam has similar testimony from Racket (neé PLT-Scheme).
Very much so -- I've encountered places where Racket's semantics for
keyword arguments (which is similar to what Allen proposes for ES6)
ends up causing the entire set
This is also a shortcut to making a dense array of a given size.
Array.apply(null, Array(5)) // [undefined, undefined, undefined, undefined,
undefined]
Array(5).map(...) // won't do anything with a sparse array
Array.apply(null, Array(5)).map(Function.prototype.call.bind(Number)) //
The wiki says that this should fill the array with 'undefined' (I believe
the spec draft aims to say the same, but I can't tell where this is
established).
The same runtime semantics routines are used for both default parameter
initialization and for initializing array destructurings in
The examples cited are arguably cases where the built-in behaviour is
unintuitive to many JavaScript developers, because it doesn't match their
expectation with user code functions and most other built-ins. I don't
view any of the cases listed as validation that we would *want* that
, Brendan Eich bren...@mozilla.com,
David Herman dher...@mozilla.com, Sam Tobin-Hochstadt sa...@ccs.neu.edu
Subject: undefined being treated as a missing optional argument
A few months ago we had some long discussions about what it means to pass
undefined as the value of an optional argument
On Apr 11, 2012, at 7:01 PM, Luke Hoban wrote:
Just to start, it means a method like:
Array.prototype.fill = function(value=null) {
this.forEach((v,i)=this[i]=value)}
wouldn't do the obvious thing when called as:
someArray.fill(undefined)
I think it is debatable what is obvious in
38 matches
Mail list logo