Closed
Description
When a function has multiple optional arguments, callers of the function must use undefined
to get the default, optional value.
Proposal
Add a syntax allowing function arguments to be passed by name. Unless there is a better suggestion, I propose the use of :=
. This would be sugar, and rewrite the call site to invoke the function properly. A syntax error would be thrown if the argument name was not a specified parameter.
argumentName := value
Example syntax:
function func(a, b=2, c=3)
{
// Do work
}
// Proposed syntax
func(c:=4, a:=1);
// Results in the following javascript being output:
func(1, void 0, 4);
// Syntax error - Multiple specifications for argument 'a'
func(1, a:=1);
// Syntax error - 'd' is not a function parameter
func(1, d:=4);
// Valid syntax
func(a:=1);
// Rewrites to
func(1);