diff --git a/assignments/lambda-classes.js b/assignments/lambda-classes.js index 71acfca0e..18e1a4eb1 100644 --- a/assignments/lambda-classes.js +++ b/assignments/lambda-classes.js @@ -1 +1,12 @@ // CODE here for your Lambda Classes +class Person { + constructor(props) { + this.name = props.name; + this.age = props.age; + this.location = props.location; + this.gender = props.gender; + } + + speak() { + + } \ No newline at end of file diff --git a/assignments/prototype-refactor.js b/assignments/prototype-refactor.js index e55ae39c0..3f254613b 100644 --- a/assignments/prototype-refactor.js +++ b/assignments/prototype-refactor.js @@ -2,40 +2,66 @@ // Today your goal is to refactor all of this code to use ES6 Classes. // The console.log() statements should still return what is expected of them. -function GameObject(options) { - this.createdAt = options.createdAt; - this.dimensions = options.dimensions; -} +//function GameObject(options) { + class GameObject { + constructor(options) { + this.createdAt = options.createdAt; + this.dimensions = options.dimensions; + } + destroy() { + return `${this.name} was removed from game.`; + } + } + -GameObject.prototype.destroy = function() { - return `Object was removed from the game.`; -}; -function CharacterStats(characterStatsOptions) { - GameObject.call(this, characterStatsOptions); - this.hp = characterStatsOptions.hp; - this.name = characterStatsOptions.name; -} +//GameObject.prototype.destroy = function() { + //return `Object was removed from the game.`; +//}; -CharacterStats.prototype = Object.create(GameObject.prototype); +//function CharacterStats(characterStatsOptions) { + //GameObject.call(this, characterStatsOptions); -CharacterStats.prototype.takeDamage = function() { + class CharacterStats extends GameObject { + constructor(characterStatsOptions) { + super(characterStatsOptions); + this.hp = characterStatsOptions.hp; + this.name = characterStatsOptions.name; +} +takeDamage() { return `${this.name} took damage.`; -}; - -function Humanoid(humanoidOptions) { - CharacterStats.call(this, humanoidOptions); - this.faction = humanoidOptions.faction; - this.weapons = humanoidOptions.weapons; - this.language = humanoidOptions.language; } +} + +//CharacterStats.prototype = Object.create(GameObject.prototype); -Humanoid.prototype = Object.create(CharacterStats.prototype); +//CharacterStats.prototype.takeDamage = function() { + // return `${this.name} took damage.`; +//}; -Humanoid.prototype.greet = function() { - return `${this.name} offers a greeting in ${this.language}.`; -}; +//function Humanoid(humanoidOptions) { + //CharacterStats.call(this, humanoidOptions); + //this.faction = humanoidOptions.faction; + // this.weapons = humanoidOptions.weapons; + /// this.language = humanoidOptions.language; +//} +//Humanoid.prototype = Object.create(CharacterStats.prototype); + +//Humanoid.prototype.greet = function() { + //return `${this.name} offers a greeting in ${this.language}.`; +//}; +class Humanoid extends CharacterStats { + constructor(humanoidOptions) { + super(humanoidOptions); + this.faction = humanoidOptions.faction; + this.weapons = humanoidOptions.weapons; + this.language = humanoidOptions.language; + } + greet() { + return `${this.name} offers a greeting in ${this.language}.`; + } +} const mage = new Humanoid({ createdAt: new Date(), dimensions: {