Named Paramters

Michał Wadas michalwadas at
Fri Jul 31 15:00:21 UTC 2015

Proposal that do not conflict with minimifiers:

- Functions have optional named parameters in any place of argument
definition. Optionality is defined by presence of hash character at
beginning of parameter name. Optional parameters CAN be placed after
rest parameter. These parameters can be accessed by name or by

function foo(bar, #qaz, boo) {
return [bar, qaz, boo];
foo(1,2,3); // [1,2,3]
foo(#qaz: 3, 4, 1); // [4,3,1] or [4,1,undefined] or throw?

function faz(bar, ...baz, #qoo) {
return [bar, ...baz, qoo];
faz(1,2,3,4,#qoo:5); // [1,2,3,4,5]

function print(...toPrint, #delimiter=',', newLine='\n') {
let delimiter = ':';
print(1, 2, 3, 4, 5,#{delimiter}); // prints '1:2:3:4:5\n'


Possible solutions for nonexistant optional argument (eg. foo(#nope:null) ):
- throw (probably the worst solution )
- define `arguments[Symbol.optionals]` object (great for passing
optional arguments)
- allow syntax for "rest optional parameters"
- ignore

Some problems:
- probably this syntax can not be transpiled in general case
- there is no intuitive behavior for ` print (1,2, #delimiter:' ',
- how will `.apply` work? Third argument with optional arguments?
`Symbol.optionals`  property on second argument (good for
seaminglessly passing `arguments`, but it doesn't sound like good idea
for arrays)?.

Any thoughts?

More information about the es-discuss mailing list