1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| var Monster = Item.extend({ construct: function(name, dangerous){ Item.construct.call(this, name); this.dangerous = dangerous; }, kick: function(){ if (this.dangerous){ alert(this.name + " bites your head off"); } else{ alert(this.name + " squeaks and runs away"); } } });
var DetailedMonster = DetailedItem.extend({ construct: function(name, description, dangerous){ DetailedItem.construct.call(this, name, dangerous); Monster.construct.call(this, name, dangerous); }, kick: Monster.kick });
var giantSloth = DetailedMonster.create( "the giant sloth", "it is quietly hanging from a tree, munching leaves", false); giantSloth.kick();
|