Could add f{} as sugar for f({}), and make engines optimize f{}? (no
positional arguments though)
On 31/07/15 12:00 PM, Michał Wadas wrote:
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
position:
```
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') {
console.log(toPrint.join(delimiter)+newLine);
}
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:' ',
#{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?
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP
IP and put it here>. If you do not agree with this, DO NOT REPLY.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss