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
54 changes: 50 additions & 4 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 Down Expand Up @@ -41,7 +43,49 @@

// Test you work by un-commenting these 3 objects and the list of console logs below:

/*
function GameObject(attr) {
this.createdAt = attr.createdAt;
this.name = attr.name;
this.dimensions = attr.dimensions;

}

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



function CharacterStats (charAttr) {
GameObject.call(this, charAttr);
this.healthPoints = charAttr.healthPoints;
this.name = charAttr.name;
}


CharacterStats.prototype = Object.create(GameObject.prototype);

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




function Humanoid (humAttr) {
CharacterStats.call(this, humAttr);
this.team = humAttr.team;
this.weapons = humAttr.weapons;
this.language = humAttr.language;
}

Humanoid.prototype = Object.create(GameObject.prototype);
Humanoid.prototype = Object.create(CharacterStats.prototype);

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

const mage = new Humanoid({
createdAt: new Date(),
dimensions: {
Expand Down Expand Up @@ -92,6 +136,8 @@
language: 'Elvish',
});



console.log(mage.createdAt); // Today's date
console.log(archer.dimensions); // { length: 1, width: 2, height: 4 }
console.log(swordsman.healthPoints); // 15
Expand All @@ -102,7 +148,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: 45 additions & 7 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
/* 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 On console with .this we can see everything in browser what javascript created for that
* 2. Implicit Binding In this principle .this refers to object left of the dot.
* 3. Explicit Binding with .apply or .call methods pass a new Object
* 4. New Binding with constructor function we can construct a new object
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding

function car (sound){
console.log(this);
return sound;
}

car('Vrooooom!');
var carSound='Vrooooom!';

//---------------------------------------------------------------
// Principle 2

// code example for Implicit Binding

let myCusine = {
name:'Kebab',
ingredients: 'Lamb meat',
nameOfthedish: function(){
// console.log('${this.name} made from ${this.ingredients}');
console.log(this.name +" made from "+this.ingredients);
}
}
myCusine.nameOfthedish();
//---------------------------------------------------------------
// Principle 3

// code example for New Binding

function GermanCar(brand){
this.germanBrand = brand;
}

let myGermanCar = new GermanCar('Mercedes is made in Germany');
console.log(myGermanCar.germanBrand);
//--------------------------------------------------------------------

// Principle 4

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

function airline () {
console.log(this.name);
}

let myAirline = {
name: 'Turkish Airlines',
airplane: 'Boeing-777'
}

airline.call(myAirline);