Last active
July 1, 2016 10:45
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//敵を作る | |
function Teki(n){ | |
this.name = n; | |
} | |
//現れる | |
Teki.prototype.appear = function(){ | |
console.log(this.name+"が あらわれた!"); | |
}; | |
//攻撃 | |
Teki.prototype.attack = function(){ | |
console.log(this.name+"のこうげき!ダメージをうけた!"); | |
}; | |
//ドラゴンを作る | |
function Dragon(){ | |
Teki.apply(this,arguments); | |
} | |
Dragon.prototype = new Teki; | |
//ドラゴンの攻撃は強い | |
Dragon.prototype.attack = function(){ | |
console.log(this.name+"のこうげき!大ダメージをうけた!"); | |
} | |
var zako = new Teki("ザコ"); //インスタンスをつくる | |
var boss = new Dragon("ボス"); | |
zako.appear(); //ザコ現れる | |
boss.appear(); //ボス現れる | |
zako.attack(); //ザコの攻撃 | |
boss.attack(); //ボスの攻撃 | |
//出力結果 | |
ザコが あらわれた! | |
ボスが あらわれた! | |
ザコのこうげき!ダメージをうけた! | |
ボスのこうげき!大ダメージをうけた! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment