prototypeを知る
716 ワード
<script type="text/javascript">
function Person(name,sex,birthday)
{
this.name =name;
this.sex = sex;
this.birthday = birthday;
}
Person.prototype={
sayHi:function(){
alert("Hi ! I am "+this.name);
},
getNameAndSex:function(){
alert(this.name+"_"+this.sex);
}
}
var person1 = new Person('mtea','boy','2011-02-03');
var person2 = new Person('xiaotea','boy','2011-02-04');
person1.sayHi();
person2.getNameAndSex();
</script>