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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ This challenge focuses on using the `this` keyword as well as getting comfortabl

**Follow these steps to set up and work on your project:**

* [ ] Create a forked copy of this project.
* [ ] Add your project manager as collaborator on Github.
* [ ] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [ ] Create a new branch: git checkout -b `<firstName-lastName>`.
* [ ] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [ ] Push commits: git push origin `<firstName-lastName>`.
* [x] Create a forked copy of this project.
* [x] Add your Team Leader as collaborator on Github.
* [x] Clone your OWN version of the repository (Not Lambda's by mistake!).
* [x] Create a new branch: git checkout -b `<firstName-lastName>`.
* [x] Implement the project on your newly created `<firstName-lastName>` branch, committing changes regularly.
* [x] Push commits: git push origin `<firstName-lastName>`.

**Follow these steps for completing your project.**

* [ ] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [ ] Add your project manager as a reviewer on the pull-request
* [x] Submit a Pull-Request to merge <firstName-lastName> Branch into master (student's Repo). **Please don't merge your own pull request**
* [x] Add your project manager as a reviewer on the pull-request
* [ ] Your project manager will count the project as complete by merging the branch back into master.

## Assignment Set Up
Expand Down
44 changes: 42 additions & 2 deletions assignments/prototypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,38 @@
* destroy() // prototype method that returns: `${this.name} was removed from the game.`
*/

function GameObject(){
this.createdAt = 10;
this.name = 'Mummy';
this.dimensions = 5.5;
// Make destroy prototype method somehow
}

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() {
this.healthPoints= 100;
// Make a takeDamage prototype method somehow
}

CharacterStats.prototype = Object.create(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,6 +57,21 @@
* should inherit destroy() from GameObject through CharacterStats
* should inherit takeDamage() from CharacterStats
*/

function Humanoid() {
this.team = Red;
this.weapons = 'Baseball bat';
this.language = 'Japanese';
// The takeDamage function needs to be written as prototype as well.
}

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

Humanoid.prototype.greet = function(){

return '${this.name} offers a greeting in $[this.language]';
}

/*
* Inheritance chain: GameObject -> CharacterStats -> Humanoid
Expand All @@ -41,7 +81,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 +142,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
46 changes: 41 additions & 5 deletions assignments/this.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,62 @@
/* The for principles of "this";
* in your own words. explain the four principle for the "this" keyword below.
*
* 1.
* 2.
* 3.
* 4.
* 1. Binding done to the Javascript default window, and all of the different functions that are assoicated with the default window
* 2. The keyword this is tied to the object that invokes it on the left hand side of the dot accessor.
* 3. It is like using a cookie cutter to make new cookies molds. The cutter will only make new cookie shapes from the same dough, and with other defined properties
* 4. These are bindings that use the call or apply method.
*
* write out a code example of each explanation above
*/

// Principle 1

// code example for Window Binding
console.log(this);

//checkWindow ('test');

// Principle 2

// code example for Implicit Binding

const obj = {

name: 'Trevor',
height: 5.9,
outputValues: function() {
console.log(this.name + ' is '+ this.height);
}
};

obj.outputValues();

// Principle 3

// code example for New Binding

function house(count, size) {

this.count = count;
this.size = size;
this.OpenDoor = function() {
console.log(this.count + this.size);
console.log(this);
}
};

const lovelyAbode = new house(10, 1500000);
lovelyAbode.OpenDoor();

const uglyAbode = new house(1, 2000);
uglyAbode.OpenDoor();

// Principle 4

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

//lovelyAbode.OpenDoor.call();
//lovelyAbode.OpenDoor.apply();

lovelyAbode.OpenDoor.call(uglyAbode);
lovelyAbode.OpenDoor.apply(uglyAbode, []);