Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Last active July 1, 2016 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/9f8e5ccb43b3d25093d6c1cbfc5c72e5 to your computer and use it in GitHub Desktop.
Save ksakae1216/9f8e5ccb43b3d25093d6c1cbfc5c72e5 to your computer and use it in GitHub Desktop.
//敵を作る
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