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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
43 changes: 41 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@
Each constructor function has unique properties and methods that are defined in their block comments below:
*/


function GameObject(attributes) {
this.createdAt = attributes.createdAt, //parent object//
this.name = attributes.name,
this.dimensions = attributes.dimensions
}

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

function CharacterStats(characterStatsAttributes){
GameObject.call(this, characterStatsAttributes), //binds to parent //
this.healthPoints = characterStatsAttributes.healthPoints

};

CharacterStats.prototype = Object.create(GameObject.prototype); // new binding used to inherit from parent //


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

function Humanoid(humanoidAttributes){
CharacterStats.call(this, humanoidAttributes); // binds to child //
this.team = humanoidAttributes.team,
this.weapons = humanoidAttributes.weapons,
this.language = humanoidAttributes.language

}

Humanoid.prototype = Object.create(CharacterStats.prototype); //inherits from child //

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


/*
=== GameObject ===
* createdAt
Expand Down Expand Up @@ -41,7 +80,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 +141,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
61 changes: 50 additions & 11 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.
*
* write out a code example of each explanation above
*/
// The for principles of "this";
// * in your own words. explain the four principle for the "this" keyword below.

// * 1. Window binding : 'this' goes to the window/console object

// * 2. Implicit binding : when a function references the object to the left of the dot (.)

// * 3. New binding : used in conjunction with a constructor function, using the 'new' keyword will make am enitrely new object with the values inside the parentheses.

// // * 4. Explicit binding : use call or apply to change what 'this' points to

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


// Principle 1

// code example for Window Binding

function favColor(color) {
console.log(this);
return color;
}

favColor("Green");

// Principle 2

// code example for Implicit Binding

let myName = {
name: 'Josh',
sayHi: function() {
console.log(this.name);
}
}

myName.sayHi()

// Principle 3

// code example for New Binding

let Shirt = function(size, brand, color){
this.size = size,
this.brand = brand,
this.color = color
}

let newShirt = new Shirt('XL', 'Vans','Blue');

console.log(newShirt);

// Principle 4

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

let four = function(){
console.log(`this is the this ${this.name}.`)
}

let explict = {
name: 'Hi, I am this!',
};

four.call(explict);