Bootstrap

ES6-解构赋值 -对象默认值

1、对象中的属性值严格相等,undefined 默认值生效

对象是空=undefined

<script>
var {x = 3} = {};//x=3

var {x, y = 5} = {x: 1};//y=5

var {x: y = 3} = {};//y=3

</script>

2、对象中的属性值不等于空,可以覆盖默认值

<script>
var {x: y = 3} = {x: 5};//y=5

</script>

3、对象属性为null,已知null和undefined不严格相等,默认值不生效--

<script>
var {x = 3} = {x: undefined};//x=3
var {x = 3} = {x: null};//x=nulls

</script>

;