Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions assignments/lambda-classes.js
Original file line number Diff line number Diff line change
@@ -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() {

}
76 changes: 51 additions & 25 deletions assignments/prototype-refactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down