js定义对象的2中方法及示例
<!DOCTYPE html>
<html> <body> <script> //两种定义对象的方法 //方法一 person=new Object(); person.firstname="Bill"; person.lastname="Gates"; person.age=56; person.eyecolor="blue"; document.write(person.firstname + " is " + person.age + " years old."+"<br/>"); /*方法二*/ function persond(firstname,lastname,age,eyecolor) { this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; } myFather=new persond("Bill","Gates",56,"blue"); document.write(myFather.firstname + " is " + myFather.age + " years old."); </script> </body> </html>