repeated parameter names and default values

David Bruant bruant.d at
Thu Sep 27 09:45:57 PDT 2012

...this is how I discovered that, in non-strict mode, it's possible to
define a function where 2 arguments have the same name...

Le 27/09/2012 18:19, Allen Wirfs-Brock a écrit :
> Consider
>    function f(a, b=a, a=3, c=a) {
The most positive adjective I can find to describe this like is:
If I'm ever in a team where a dev writes such a line, I will kill this
dev with my bare hands :-)
When writing 'c=a', what was the intention of the developer? Maybe the
third arg has been renamed to 'a' by mistake during a refactoring,
introducing a subtle bug.

When using the same argument name several times with default values,
what about throwing an SyntaxError at parse time regardless of
strictness? It would follow what's been done with strict mode.

Also, is there really a value in being able reuse a previous argument to
define the value of another argument?
The idea of "for the second argument, use its value unless it's
undefined in which case, reuse the value of the first argument" smells
like poorly designed code or API, but I'm curious if some can show a
case where it's legitimate.


More information about the es-discuss mailing list