其他分享
首页 > 其他分享> > js ES9对象展开

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: '幽冥一击'}

 

标签:...,console,log,ES9,js,运算符,const,root,展开
来源: https://www.cnblogs.com/jerryfish/p/15340992.html