ES6-对象扩展运算符

<html>

<head>
    <title>ES6-对象扩展运算符</title>
</head>

<body>




    <script>
        // 1、拷贝对象
        {
            let person1 = { name: "Amy", age: 15 };
            let someone = { ...person1 };
            console.log(someone);  //{name: "Amy", age: 15}
            console.log(person1 == someone);//false  只是做了属性赋值。还是2个对象
        }
        console.log("----------------------拷贝对象:分割线-------------------------------");
        // 1、合并对象
        {
            let person1 = { name: "Amy" };
            let someone = {  age: 15 };
             let ming={...person1,...someone};
            console.log(ming);  //输出{name: "Amy", age: 15}
        }


    </script>
</body>

</html>

 

posted @ 2020-09-26 22:11  KwFruit  阅读(97)  评论(0编辑  收藏  举报