const o = {a:null, b:'', c:0, d: true, e: undefined, f: '123'}
const {a = {}, b = '00', c = 1, d = false, e = [], f = {}, g = {} } = o
console.log(a,b,c,d,e,f,g)
输入结果
null "" 0 true [] "123" {}
只有 undefined 的值才会使用默认值
const o = {a:null, b:'', c:0, d: true, e: undefined, f: '123'}
const {a = {}, b = '00', c = 1, d = false, e = [], f = {}, g = {} } = o
console.log(a,b,c,d,e,f,g)
输入结果
null "" 0 true [] "123" {}
只有 undefined 的值才会使用默认值
本文标题:关于 es6 解构默认值问题
本文链接:https://www.haomeiwen.com/subject/fymgwktx.html
网友评论