javascipt很灵活,创建对象有以下几种方式。
第一种:
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}
myFather=new person("Bill","Gates",56,"blue");
第二种:
person={firstname:"Bill",lastname:"gates",age:56,eyecolor:"blue"}
第三种:
var person={};
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
person.eyecolor="blue";
第四种:和第三种类似
person=new Object();
person.firstname="Bill";
person.lastname="Gates";
person.age=56;
person.eyecolor="blue";