Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//敵を作る
function Teki(){
this.hp = 100;
}
//ドラゴンを作る
function Dragon(){
Teki.apply(this,arguments);
}
Dragon.prototype = new Teki;
//攻撃してHPを教えてもらう
Dragon.prototype.attack = function(){
console.log("ドラゴンの攻撃! ドラゴンのHPは"+this.hp+"だ!");
};
var boss = new Dragon(); //インスタンスをつくる
boss.attack(); //攻撃してもらう
//出力結果
ドラゴンの攻撃! ドラゴンのHPは100だ!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.