<!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>

 

相关文章:

  • 2022-01-02
  • 2022-02-21
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-06-16
  • 2022-01-01
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2021-09-26
  • 2022-01-06
  • 2022-12-23
  • 2021-09-24
  • 2021-11-23
  • 2021-12-27
相关资源
相似解决方案