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
42 changes: 36 additions & 6 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor functions with their correct inheritance hierarchy.
Object oriented design is commonly used in video games. For this part of the assignment you will be implementing several constructor
functions with their correct inheritance hierarchy.

In this file you will be creating three constructor functions: GameObject, CharacterStats, Humanoid.

At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test your constructor functions.
At the bottom of this file are 3 objects that all end up inheriting from Humanoid. Use the objects at the bottom of the page to test
your constructor functions.

Each constructor function has unique properties and methods that are defined in their block comments below:
*/
Expand All @@ -15,14 +17,30 @@
* 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.dimensions = attributes.dimensions;
this.name = attributes.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(childAttributes){
this.healthPoints = childAttributes.healthPoints;
GameObject.call(this, childAttributes)
}
CharacterStats.prototype = Object.create(GameObject.prototype)//Child.prototype = Object.create(Person.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 +50,17 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid (chAttributes){
this.weapons = chAttributes.weapons;
this.language = chAttributes.language;
this.team = chAttributes.team
CharacterStats.call(this, chAttributes)
}
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 +69,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 All @@ -58,6 +86,7 @@
language: 'Common Tongue',
});


const swordsman = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand All @@ -75,6 +104,7 @@
language: 'Common Tongue',
});


const archer = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -102,7 +132,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
52 changes: 46 additions & 6 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
/* 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 -what a keyword is referrencing to in awindow object by default
* 2. Impicit Binding - left side of the dot for example: looks at myCar when you invoke myCar.car(). only objects with methods
* 3. New Binding -calling function with the new keyword the functions object keys are bound to the new function
* 4. Explicit Binding - uses the call, apply, bind. we invoke a function inside of object.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
const homeType = function(){
console.log(this.home);
};
const type = {
home : "flat"
};
homeType()


// Principle 2

// code example for Implicit Binding
const race = {
car: "Ferrari",
engine: "v8",
wheel: "round",
cheer: function(){
console.log (`it has a ${this.engine} engine!`)
}
}

race.cheer()



// Principle 3

// code example for New Binding
// code example for New Binding
const Me = function ( name, car, food){
this.name = name,
this.carType = car,
this.favFood = food
};
const clone = new Me("antonio", "mustang", "pizza" )
console.log(clone)





// Principle 4

// code example for Explicit Binding
// code example for Explicit Binding
const study = function (){
console.log(`${this.lan3} is hard`)
}
const language = {
lan1: "Python",
lan2: "Java",
lan3: "Javascript"
};
study.call(language);