Sunday, April 22, 2007

Javascript クラス 継承の例

<script type=text/javascript>
<!--

function Team(name,members){
this.name = name;
this.members = members;
}

Team.prototype.add = function(members){
this.members += members;

};

function TeamAAA (name,members) {
this.name = name;
this.members = members;
}

TeamAAA.prototype = new Team();
TeamAAA.prototype.leave = function(members){
this.members -= members;

};

baseball = new TeamAAA("2軍",11);
baseball.leave(3);
document.write("Team name:"+ baseball.name + ", members:"+baseball.members);

//-->
</script>


JavaScript継承パターンまとめ

No comments: