Javascript 方法有多个参数有默认值,但是只想为其中某个参数赋值
例子:
function log(a, b = 2, c = 3, d = 4) {
console.log(a, b, c, d)
}
log(1); // output: 1 2 3 4
log(1, 3, 6, 9); //1 3 6 9
log(1, undefined, 9, 12); // 1 2 9 12
log(1, undefined, 0); // 1 2 0 4
log(1, undefined, undefined, 16); // 1 2 3 16
就是在你想略过的那个参数用 undefined
替换