I ran into a case when using a community built SDK around the Investec API where I need to skip a function argument as the skipped argument was not necessary so I set it to undefined in order to the get to the next argument that the function needs.
For example:
function helloWorld(a, b , c) {
// does something based on the arguments
}
helloWorld('hello', undefined, 'world')
The above got me thinking about how array destructuring works where I can do this:
const [a,,b] = [1,2,3]
Where I can skip the 1-index element in the array so why can't I do that when passing function arguments like this:
function helloWorld(a, b, c) {
}
helloWorld('hello',, 'world')
The skipped argument would be automatically set to undefined and the syntax falls in line with what is possible with array destructuring.
An optional argument shouldn't precede a required one - the best solution here is probably an options object if there's more than one optional arg at a time.
@oleedd I agree, proposals are up in the air and not aimed to be a solution. Array destructuring can be solved in other ways but the features was added due to consensus by the community, I still believe my proposal to be valid in the context of modern JS.
I replied to ljharb, which took it as a problem which needs an existing solution, not as a proposal. I had to quote...
I wanted to propose this at the time you did. But first I opened a question: Why no ability to skip arguments at calling functions?
If you proposed not after reading my question, then it is some wonderful coincidence (even the same day).
Wow. Then this improbable coincidence is a sign of higher powers.
So, esteemed delegates, lets discuss this proposal. It is not potentially regrettable unlike array methods.