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
44 changes: 39 additions & 5 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,34 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function GameObject(object){
this.createdAt = object.createdAt,
this.name = object.name,
this.dimensions = object.dimensions
};//object
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
*/
function CharacterStats(stats){
GameObject.call(this,stats);
this.healthPoints = stats.healthPoints;

};//charstats
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.) ===
Expand All @@ -32,16 +54,29 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

/*

function Humanoid(attrr){

CharacterStats.call(this,attrr)
this.team = attrr.team,
this.weapons = attrr.weapons,
this.language = attrr.language

};//humanoid

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.
* Instances of CharacterStats should have all of the same properties as GameObject.
*/

// 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 @@ -101,8 +136,7 @@
console.log(archer.language); // Elvish
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.
*/
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
45 changes: 39 additions & 6 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.

* 1. Window binding - default value of "this" if no other rule is used.


* 2. Implicit Binding - if the function is invoked using a method then "this" is referencing whats left of the dot.


* 3. new binding - creates a new function that links the "this" to the new function


* 4. Explicit binding - call/apply/bind/ to directly choose what "this" refers too.
*
* 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

let froggy = {
name: "toad",
age: 1,
noise:"RIBBBBBITTT",
ribbit: function(){
console.log(`toad does a ${this.noise} he is only ${this.age}`);
}
}
froggy.ribbit();

// Principle 3

// code example for New Binding
function Grapes(param1,param2){
this.item1 = param1;
this.item2 = param2;
}
myFavGrapes = new Grapes("green","red")

console.log(`my first favorite type of grape is ${myFavGrapes.item2} my second fav is ${myFavGrapes.item1}`)
// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
function treeTalk(){
console.log(`this ${this.type} tree is ${this.width} wide. wow!!`)
}
const tree = {
height:"100ft",
width:"600ft",
type:"oak"
}

treeTalk.call(tree);