声明(创建)对象

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript 对象</h2>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. var person = {
  11. firstName : "Bill",
  12. lastName : "Gates",
  13. age : 62,
  14. eyeColor : "blue"
  15. };
  16.  
  17. document.getElementById("demo").innerHTML =
  18. person.firstName + " is " + person.age + " years old.";
  19. </script>
  20.  
  21. </body>
  22. </html>