注意JavaScript中对象类别的定义,使用function来定义对象类别,初始化对象使用new操作符
functionPerson(name,age){
this.name=name;
this.age=age;
this.toString=function(){
document.writeln("[name]:"+this.name+"
"+"[age]:"+this.age);
}
}
完整的简单HTML
functionPerson(name,age){
this.name=name;
this.age=age;
this.toString=function(){
document.writeln("[name]:"+this.name+"
"+"[age]:"+this.age);
}
}
varperson=newPerson();
person.name="robbin";
person.age=30;
person.toString();