Skip to content

Jarrod skahill #737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
41 changes: 32 additions & 9 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,29 @@
Each constructor function has unique properties and methods that are defined in their block comments below:
*/

/*
=== GameObject ===
* createdAt
* name
* 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 ===
* healthPoints
* takeDamage() // prototype method -> returns the string '<object name> 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.) ===
Expand All @@ -32,6 +41,20 @@
* 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
Expand All @@ -41,7 +64,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 @@ -102,7 +125,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
53 changes: 46 additions & 7 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,65 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. New binding is when a new variable creates an object and the "this" keyword directs to it
* 2. 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.
* 3. Implicit Binding is when a function is given the keyword "this" to allow invoking.
* 4. Explicit Binding is when we descriptivly tell the engine to use call, apply, or bind when pointing to a specific value, these three words can invoke fuctions with certain values of "this"
*
* write out a code example of each explanation above
*/

// 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

// 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

// 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 Explicit Binding
// code example for New Binding