Skip to content

finished project #755

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 1 commit 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
38 changes: 36 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,41 @@

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

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

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

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

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

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

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

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

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 @@ -102,7 +136,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
51 changes: 46 additions & 5 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Global Binding - the value of "this" is the window or console.
* 2. Implicit Binding - "this" refers to the object that the method is acting on
* 3. New Binding - "this" refers to the new object created by the constructor function
* 4. Explicit Binding - whenever call or apply is used "this" is explicitly bound
*
* write out a code example of each explanation above
*/
Expand All @@ -13,14 +13,55 @@

// code example for Window Binding

function logHello(phrase) {
console.log(this);
return phrase;
};
logHello('Hello');

// Principle 2

// code example for Implicit Binding

let myObj = {
age: 27,
stateAge: function(name) {
console.log(`${name} is ${this.age}`);
console.log(this);
}
};

myObj.stateAge("Jack");

// Principle 3

// code example for New Binding

function stateAge(person) {
this.age = 27,
this.person = person,
this.state = function () {
return `${this.person} is ${this.age}`;
console.log (this);
};
}

const jack = new stateAge('Jack');
jack.state();

// Principle 4

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

function stateAge(person) {
this.age = 27,
this.person = person,
this.state = function () {
return `${this.person} is ${this.age}`;
console.log (this);
};
}

const jim = new stateAge('Jack');
const jill = new stateAge('Jill');
jim.state.call(jill);