31.浅拷贝.html 686 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. /**
  11. * 浅拷贝:新值复制旧值得内容,修改新值时看旧值是否发生改变
  12. * 如果发生改变就证明是浅拷贝。
  13. */
  14. var obj1 = {
  15. name:'Lucy',
  16. age: 22,
  17. speak:function() {
  18. console.log("我是"+this.name,"我爱学习么");
  19. }
  20. }
  21. var obj2 = obj1;
  22. obj2.name = 'zjr';
  23. console.log(obj1,'obj1');
  24. console.log(obj2,'obj2');
  25. </script>
  26. </body>
  27. </html>