[Proposal] Optional function arguments
function myfunc (arg, [options], callback)
...
->
function myfunc (arg, _options, _callback) {
if (typeof _callback === "undefined") {
_callback = _options;
_options = undefined;
}
}
Or something like that...
This would greatly simplify declaration of functions with optional arguments that some framework use lately (like NodeJS)
Related: https://github.com/jashkenas/coffee-script/issues/1091
Needed:
- syntax
- compilation strategy
@ceymard Why not just void?
function myfunc (arg, [options], callback)
void
How does void solve my problem ?
Uh, I misunderstood your proposal, sorry.
Optional parameters without named arguments seems like it could get pretty hairy, no? Personally, I think any new dynamically-typed languages should require named parameters (after the first) - code is about reading, not writing.