创建用于对象的模板

  1. <html>
  2. <body>
  3.  
  4. <script type="text/javascript">
  5.  
  6. function person(firstname,lastname,age,eyecolor)
  7. {
  8. this.firstname=firstname
  9. this.lastname=lastname
  10. this.age=age
  11. this.eyecolor=eyecolor
  12. }
  13.  
  14. myFather=new person("John","Adams",35,"black")
  15.  
  16. document.write(myFather.firstname + " 的年龄是 " + myFather.age + " 岁。")
  17.  
  18. </script>
  19.  
  20. </body>
  21. </html>