@@ -36,7 +36,7 @@ Prototype Refactor
3636 // };
3737
3838
39- // Object Refactored:
39+ // GameObject Object Refactored:
4040
4141 class GameObject {
4242 constructor ( GameObj ) {
@@ -56,36 +56,36 @@ Prototype Refactor
5656}
5757
5858
59- 60- 61- 62- 6359 // === CharacterStats ===
60+ // function CharacterStats(charAttrs) {
61+ // GameObject.call(this, charAttrs);
62+ // this.healthPoints = charAttrs.healthPoints;
63+ // };
64+ 65+ 66+ // CharacterStats Refactored:
67+ 68+ class CharacterStats extends GameObject {
69+ constructor ( charAttrs ) {
70+ super ( GameObj ) ;
71+ this . healthPoints = charAttrs . healthPoints ;
72+ }
6473
6574
66- function CharacterStats ( charAttrs ) {
67- GameObject . call ( this , charAttrs ) ;
68- this . healthPoints = charAttrs . healthPoints ;
69- } ;
70- 71- CharacterStats . prototype = Object . create ( GameObject . prototype ) ;
75+ // CharacterStats.prototype = Object.create(GameObject.prototype);
7276
73- CharacterStats . prototype . takeDamage = function ( ) {
77+ // CharacterStats.prototype.takeDamage = function () {
78+ // return `${this.name} took damage`;
79+ // }
80+ 81+ 82+ 83+ // CharacterStats Prototype Refactored:
84+ 85+ takeDamage ( ) {
7486 return `${ this . name } took damage` ;
7587 }
76- 77- // function CharacterStats(CharStats) {
78- // CharacterStats.prototype = Object.create(GameObject.prototype);
79- // this.healthPoints = CharStats.healthPoints;
80- 81- 82- 83- // // should inherit destroy() from GameObject's prototype
84- // };
85- 86- // CharacterStats.prototype.takeDamage = function() {
87- // return `${this.name} took damage.`; // prototype method -> returns the string '<object name> took damage.'
88- // }
88+ }
8989
9090
9191
0 commit comments