1.
function log(x, y = 'world') { console.log(x, y) }
这里计算的是是否有值传入 y,如果没有(值为 undefined)则设置 y 的默认值为 world
undefined
world
2.
function Point(x = 0, y = 0) { this.x = x this.y = y } const p = new Point() console.log(p) //Point { x: 0, y: 0 }
3.
let x = 99 function foo(p = x + 1) { console.log(p) } foo() // 100 x = 100 foo() // 101
Last updated 5 years ago
Was this helpful?