- 解构赋值 默认值
var x = 200, y = 300, z = 100;
var o1 = { x: { y: 42 }, z: { y: z }};
({ y: x = { y: y }} = o1);
({ z: y = { y: z }} = o1);
({ x: z = { y: x }} = o1);
console.log( x.y, y.y, z.y );
300,100,42
- 解构赋值 解构默认值和参数默认值的区别
function fn ({ x = 10 } = {}, { y } = { y: 10 }) {
console.log( x, y );
}
fn( {}, {} );
10 undefind
网友评论