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
41 changes: 37 additions & 4 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,33 @@
* dimensions (These represent the character's size in the video game)
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/
function GameObject(attributes){
this.createdAt = attributes.createdAt;
this.name = attributes.name;
this.dimensions = attributes.dimensions;
};

GameObject.prototype.destroy = function(){
return `${this.name} was removed from the game.`;
}

/*
=== CharacterStats ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> took damage.'
* should inherit destroy() from GameObject's prototype
* should inherit destroy() from GameObject's prototype ?????call
*/

function CharacterStats (attributes){
GameObject.call(this, attributes);
this.healthPoints = attributes.healthPoints;
}
CharacterStats.prototype = Object.create(GameObject.prototype);

CharacterStats.prototype.takeDamage = function(){
return `${this.name} took damage.`;
}

/*
=== Humanoid (Having an appearance or character resembling that of a human.) ===
* team
Expand All @@ -32,7 +51,20 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/


function Humanoid (attributes){
CharacterStats.call(this, attributes)
this.team = attributes.team;
this.weapons = attributes.weapons;
this.language = attributes.language;
}

Humanoid.prototype = Object.create(CharacterStats.prototype);

Humanoid.prototype.greet = function (){
return `${this.name} offers a greeting in ${this.language}.`;
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -41,7 +73,7 @@

// Test you work by un-commenting these 3 objects and the list of console logs below:

/*

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -92,6 +124,7 @@
language: 'Elvish',
});


console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
Expand All @@ -102,7 +135,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
39 changes: 38 additions & 1 deletion assignments/this.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,62 @@
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
Window, not global, but looks at everything in a window.

* 2.
Implicit, this is implied to be inside of the current functional scope

* 3.
New,

* 4.
Explicit, you can use call, apply and/or bind to explicitly state where this will point to

@BrannanC BrannanC Apr 4, 2019 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look for the answer to question 3 in the training kit

*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
console.log(this)

// Principle 2

// code example for Implicit Binding
const student = {
name: "Carlos",
age: 31,
food: "lentils",
cook: function() {
return `${this.name} loves to cook ${this.food}`;
}
}
console.log(student.cook);

// Principle 3

// code example for New Binding

const Car = function(model,color,make){

this.model = model;
this.color = color;
this.make = make;
}

const mustang = new Car('1987','black','Ford')

// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding

const soldier = {
"name":"Ricky"
}

function stats(info1,info2,info3){
return `Soldier ${this.name} has experience with ${info1},${info2},${info3}.`;
}

const experience =['driving','medical', 'skydiving']