我有一个这样的功能:
function foo(a, b, c, d, e, f) {
}
为了只用 f
参数调用这个函数,我知道我应该这样做:
foo(undefined, undefined, undefined, undefined, undefined, theFValue);
有没有不那么冗长的方法?
解决方案 :
我选择了一些建议的解决方案(没有使用 helper 第三个函数)
// 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});