使用 new 创建 JavaScript 对象

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p id="demo"></p>
  6.  
  7. <script>
  8. var person = new Object();
  9. person.firstName = "Bill";
  10. person.lastName = "Gates";
  11. person.age = 50;
  12. person.eyeColor = "blue";
  13.  
  14. document.getElementById("demo").innerHTML =
  15. person.firstName + " is " + person.age + " years old.";
  16. </script>
  17.  
  18. </body>
  19. </html>