Wildcard

Claude Pache claude.pache at gmail.com
Sun Dec 30 14:40:29 PST 2012


I think that "nothing" wins over "dot" or "underscore" for marking unused positions, for one simple reason: it is implemented for years in every engines in constructs like:

var myArray = [ , , third]

So it seems more natural to me to have something like: function( , , z) { /* ... */ }

But anyway, if one day I'll need more than one unused parameter, I would first ask me seriously if it would not be better to refactor my function's signature with something like:

function f({z: z})  { /* ... */ }
f({x: first, y: second, z: third})

instead of: 

function f( , , z)  { /* ... */ }
f(first, second, third)

Claude

Le 30 déc. 2012 à 13:06, Axel Rauschmayer <axel at rauschma.de> a écrit :

> It wouldn’t be breaking if it was the only identifier that one was allowed to use multiple time, right?
> 
> But I do like the idea of the dot. Would be nice for destructuring arrays, too:
> 
> let [., ., third] = myArray;
> 
> On Dec 30, 2012, at 13:01 , Andreas Rossberg <rossberg at google.com> wrote:
> 
>> On 30 December 2012 12:50, Axel Rauschmayer <axel at rauschma.de> wrote:
>>> It would actually be nice to have that as a feature: If the variable name is
>>> `_` then it can be used multiple times. It’s a nice, self-descriptive way of
>>> saying that you don’t care about a parameter value.
>> 
>> That underscore wildcard is the exact syntax used in functional
>> languages, and very useful, I agree. In JS, that syntax would be a
>> breaking change, unfortunately. But we could use something else (e.g.
>> I proposed '.' in the past).
>> 
>> /Andreas
> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de
> 
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121230/9c8de239/attachment-0001.html>


More information about the es-discuss mailing list