JavaScript 对象是易变的

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 对象是易变的</h1>
  6.  
  7. <p>对对象副本的任何更改也将更改原始对象。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. var person = {firstName:"Bill", lastName:"Gates", age:62, eyeColor:"blue"}
  13.  
  14. var x = person;
  15. x.age = 10;
  16.  
  17. document.getElementById("demo").innerHTML =
  18. person.firstName + " is " + person.age + " years old.";
  19. </script>
  20.  
  21. </body>
  22. </html>