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
1 change: 1 addition & 0 deletions assignments/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@

<body>
<h1>JS III - Check your work in the console!</h1>
<h2>Ready</h2>
</body>
</html>
34 changes: 31 additions & 3 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
* destroy() // prototype method -> returns the string: 'Object was removed from the game.'
*/

function GameObject (data){
this.createdAt = data.createdAt;
this.dimensions = data.dimensions;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.dimensions = data.dimensions;
this.dimensions = data.dimensions;
this.name = options.name;

};


GameObject.prototype.destroy = function(object){ // this is the prototype method destroy
return `${this.name} was removed from the game.`
};
/*
=== CharacterStats ===
* healthPoints
Expand All @@ -23,6 +32,16 @@
* should inherit destroy() from GameObject's prototype
*/

function CharacterStats (data){
GameObject.call(this, data)
this.healthPoints = data.healthPoints;
this.name = data.name;
};
CharacterStats.prototype = Object.create(GameObject.prototype); //Inheriting gameObject 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 +51,17 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid(data){
CharacterStats.call(this, data) // explain what is happenning with this call?
this.team = data.team;
this.weapon = data.weapon;
this.language = data.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
* Instances of Humanoid should have all of the same properties as CharacterStats and GameObject.
Expand All @@ -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: {
Expand Down Expand Up @@ -102,7 +131,6 @@
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
59 changes: 52 additions & 7 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,71 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Global scope - When "this" is not pointing to anything created or rests in a fuction that is pointed in the global scope it will console log whatever is the browsers window or object.
* 2. Implicit Binding - Most common use of this, refers to when this is when you call this inside of an object or inside of a constructior that takes in an object as the argument.
* 3. New binding - This is when this is activated by the new keyword, when you type the new keyword it searches for a matching constructor function for the word that follows right after it, inside
- the constructor function all the this keywords are activated when the object is created,
* 4. Explicit binding - When we give context to this by sing .call or .apply methods
*
* write out a code example of each explanation above
*/
* write out a code example of each explanation above */


// Principle 1

// code example for Window Binding

function windowBinding (data){
console.log(this);
return data;
}

windowBinding();

// Principle 2

const implicitBinding = {
name: 'new',
method: function (){
console.log(`${this.name} implicit binding example`);
console.log(this);
}
};

implicitBinding.method();

// code example for Implicit Binding

// Principle 3

// code example for New Binding

function newBinding (bindMe){
this.example = 'check me';
this.bind = bindMe;
this.talk = function (){
console.log (`${this.example} ${this.bind} bra`);
console.log(this);
};
}

const example = new newBinding('this is new binding')
example.talk();

// Principle 4

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

const explicitBinding = {
name: 'Yankho',
city: 'Atlanta',
favoriteJob: 'Google'
}

function whoAmI(data){
console.log(`Hey i am a 22 year old guy named ${this.name} living in ${this.city} my dream job ${this.favoriteJob} ${data} `)
}

whoAmI.call(explicitBinding, 'deal with it');

whoAmI.apply(explicitBinding, ['deal with it']);