I have a function like this:
function foo(a, b, c, d, e, f) {
}
In order to call this function only with an f
argument, I know I should do:
foo(undefined, undefined, undefined, undefined, undefined, theFValue);
Is there a less verbose way to do this?
Solutions:
I selected some proposed solutions (without using helper third functions)
// zero - ideal one, actually not possible(?!)
foo(f: fValue);
// one - asks a "strange" declaration
var _ = undefined;
foo(_, _, _, _, _, fValue);
// two - asks the {} to be used instead of a 'natural' list of args
// - users should be aware about the internal structure of args obj
// so this option is not 'intellisense friendly'
function foo(args){
// do stuff with `args.a`, `args.b`, etc.
}
foo({f: fValue});
var _ = undefined; foo(_,_,_,_,_, theFValue);
solution is buried in this long answer. You would of course do the initial declaration of_
once, in some common utility file that you include in every js file. – ToolmakerSteve