js ES9对象展开

 rest参数与spread扩展运算符已经在ES6中引入,但是ES6没有提供对象的实现
 ES9中为对象提供了像数组一样的rest参数和扩展运算符
function connect({host, port, ...user}){
            console.log(host);//127.0.0.1
            console.log(port);//3306
            console.log(user);//Object password: "root" type: "master" username: "root"
        }
        connect({
            host:'127.0.0.1',
            port:3306,
            username:'root',
            password:'root',
            type:'master'
        })
        // 扩展运算符
        const skillOne = {
            c: '暗影冲刺'
        }
        const skillTwo = {
            h: '威吓'
        }
        const skillThree = {
            t: '巨力重击'
        }
        const skillFour = {
            e: '幽冥一击'
        }
        const spiritBreaker = {...skillOne,...skillTwo,...skillThree,...skillFour};
        console.log(spiritBreaker);//{c: '暗影冲刺', h: '威吓', t: '巨力重击', e: '幽冥一击'}

 

posted @ 2021-09-26 23:21  jerryfish  阅读(244)  评论(0编辑  收藏  举报