From 73eff29e51648ab4a78bcf5d636cc4b0400df38b Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Wed, 16 Oct 2019 15:31:03 -0700 Subject: [PATCH 1/3] finished this page --- assignments/this.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/assignments/this.js b/assignments/this.js index 969bbeeba..8d480bd50 100644 --- a/assignments/this.js +++ b/assignments/this.js @@ -1,7 +1,7 @@ /* The for principles of "this"; * in your own words. explain the four principle for the "this" keyword below. * -* 1. +* 1. Window Binding is when no other rules are present the "this" keyword will automatically implement window object, if strict mode is active it will default undefined instead. * 2. * 3. * 4. @@ -10,17 +10,49 @@ */ // Principle 1 +function hotWheel(monster){ + console.log(`I use to love` + `${this.monster}` + ` trucks`); + return monster; + +} +hotWheel(this); // code example for Window Binding // Principle 2 +let jay = { + name: "Jarrod", + says: "what's up guys!", + jaySays: function (){ + console.log(this.says) + } +} + +jay.jaySays(); // code example for Implicit Binding // Principle 3 +function fastCar(brz){ + this.thing = brz; +} + +let Car = new fastCar('brz goes 0-60 in 6.2 sec'); +console.log(Car.thing); // code example for New Binding // Principle 4 +function car(){ + console.log(this.fast); +} + +let wrx = { + brand: "subaru", + fast: "0-60 in 5.5 seconds" +} + +car.call(wrx) + // code example for Explicit Binding \ No newline at end of file From c18390664f3f4573280d4b67117727e39add3ac2 Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Wed, 16 Oct 2019 15:51:02 -0700 Subject: [PATCH 2/3] got most of the prototypes to work --- assignments/prototypes.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/assignments/prototypes.js b/assignments/prototypes.js index 5625c97cb..7e1c36f15 100644 --- a/assignments/prototypes.js +++ b/assignments/prototypes.js @@ -15,6 +15,15 @@ * 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 (mainat) { + this.createdAt = mainat.createdAt; + this.dimensions = mainat.dimensions; + this.name = mainat.name; +}; + GameObject.prototype.destroy = function() { + return `${this.name} was removed from the game.`; + }; + /* === CharacterStats === @@ -22,6 +31,14 @@ * takeDamage() // prototype method -> returns the string ' took damage.' * should inherit destroy() from GameObject's prototype */ +function CharacterStats(CharInfo) { + GameObject.call(this, CharInfo); + this.healthPoints = CharInfo.healthPoints; + this.name = CharInfo.name; +} +CharacterStats.prototype.takeDamage = function() { + return `${this.name} took damage`; +}; /* === Humanoid (Having an appearance or character resembling that of a human.) === @@ -32,6 +49,18 @@ * should inherit destroy() from GameObject through CharacterStats * should inherit takeDamage() from CharacterStats */ +function Humanoid(player1) { + CharacterStats.call(this, player1); + this.team = player1.team; + this.weapon = player1.weapon; + this.language = player1.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 @@ -41,7 +70,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: { @@ -102,7 +131,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. From ac27074caae3bff80083a82c9e31f87628fd4c12 Mon Sep 17 00:00:00 2001 From: jarrodskahill Date: Wed, 16 Oct 2019 17:00:03 -0700 Subject: [PATCH 3/3] fixed my errors, completed mvp --- assignments/prototypes.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/assignments/prototypes.js b/assignments/prototypes.js index 7e1c36f15..f50224a8d 100644 --- a/assignments/prototypes.js +++ b/assignments/prototypes.js @@ -31,11 +31,13 @@ function GameObject (mainat) { * takeDamage() // prototype method -> returns the string ' took damage.' * should inherit destroy() from GameObject's prototype */ -function CharacterStats(CharInfo) { - GameObject.call(this, CharInfo); - this.healthPoints = CharInfo.healthPoints; - this.name = CharInfo.name; +function CharacterStats(mainat) { + GameObject.call(this, mainat); + this.healthPoints = mainat.healthPoints; + this.name = mainat.name; } +CharacterStats.prototype = Object.create(GameObject.prototype); + CharacterStats.prototype.takeDamage = function() { return `${this.name} took damage`; }; @@ -49,11 +51,11 @@ CharacterStats.prototype.takeDamage = function() { * should inherit destroy() from GameObject through CharacterStats * should inherit takeDamage() from CharacterStats */ -function Humanoid(player1) { - CharacterStats.call(this, player1); - this.team = player1.team; - this.weapon = player1.weapon; - this.language = player1.language; +function Humanoid(mainat) { + CharacterStats.call(this, mainat); + this.team = mainat.team; + this.weapons = mainat.weapons; + this.language = mainat.language; } Humanoid.prototype = Object.create(CharacterStats.prototype);