Skip to content
Merged
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
45 changes: 43 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,49 @@
*/

// Test you work by un-commenting these 3 objects and the list of console logs below:
function GameObject(att){
this.createdAt = att.createdAt;
this.name = att.name;
this.dimensions = att.dimensions;
}
GameObject.prototype.destroy = function(){
console.log(`${this.name} was removed from the game`)
}


function CharacterStats(att){
GameObject.call(this, att)
this.healthPoints = att.healthPoints;

}
CharacterStats.prototype = Object.create(GameObject.prototype)
CharacterStats.prototype.takeDamage = function () {
console.log(`${this.name} took damage`)
}


function Humanoid(att){
CharacterStats.call(this, att)
CharacterStats.prototype.takeDamage.call(this, att)
GameObject.call(this, att)
this.team = att.team;
this.weapons = att.weapons;
this.language = att.language;

}
Humanoid.prototype = Object.create(CharacterStats.prototype)
//Humanoid.prototype = Object.create(CharacterStats.prototype.takeDamage)
//Humanoid.prototype = Object.create(GameObject.prototype)
Humanoid.prototype.greet = function () {
console.log(`${this.name} offers a greeting in ${this.language}`)
}







/*
const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -102,7 +143,7 @@
console.log(archer.greet()); // Lilith offers a greeting in Elvish.
console.log(mage.takeDamage()); // Bruce took damage.
console.log(swordsman.destroy()); // Sir Mustachio was removed from the game.
*/


// Stretch task:
// * Create Villain and Hero constructor functions that inherit from the Humanoid constructor function.
Expand Down
14 changes: 13 additions & 1 deletion assignments/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@
*/

// Principle 1

function birthday(when){
console.log(when);
return this;
}
birthday("082997");
// code example for Window Binding

// Principle 2
const getBirthday ={
birthday: '082997',
birth: function(time){
console.log(`${birthday} is mine yours is ${time}`)
console.log(this)
}
}
getBirthday.birth('20')

// code example for Implicit Binding

Expand Down