首页 > 其他 > 详细

es6 对象浅拷贝的2种方法

时间:2018-05-07 20:34:07      阅读:234      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="zh">

    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>es6 对象浅拷贝</title>
    </head>

    <body>
        <script type="text/javascript">
            var obj = {
                data: [11, 2, 3],
                name: mfg,
                fn: function() {}
            };
            var objNew = { ...obj
            };
            var objNew2 = Object.assign({}, obj);
            console.log(objNew === obj) //false
            console.log(objNew2 === obj) //false
            console.log(objNew.fn === obj.fn) //true
            console.log(objNew2.fn === obj.fn) //true
        </script>
    </body>

</html>

 

es6 对象浅拷贝的2种方法

原文:https://www.cnblogs.com/mengfangui/p/9004595.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!