考虑例子
var example = function(a = 10, b = 15, c) {
return c;
}
因此,我想仅使用
example
的值调用c
函数。就像是,example(20); // should return 20, without disturbing the values of a and b
如何在JavaScript中执行此操作?
最佳答案
您想要的是可以通过解构分配来实现的,但需要一些mod。如我所见,您正在使用es2015 / es6代码设置默认值。您可能会考虑:
var example = function([a = 10, b = 15, c]) {
console.log(a,b, c);
//return c;
}
example([,,20]);