Repository navigation
completed this.js #1
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
Conary36
wants to merge
2
commits into
master
Choose a base branch
from
Conary-Beckford
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,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(attrs){ | ||
| this.createdAt = attrs.createdAt; | ||
| this.name = attrs.name; | ||
| this.dimensions = attrs.dimensions; | ||
| } | ||
| GameObject.prototype.destroy = function(remove){ | ||
| console.log(`${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(healthPoints){ | ||
| GameObject.call(this, healthPoints); | ||
| this.damageAmount = healthPoints.damageAmount; | ||
| } | ||
| CharacterStats.prototype = Object.create (GameObject.prototype); | ||
| CharacterStats.prototype.takeDamage = function(){ | ||
| console.log(`${this.name} took damage`); | ||
| return `${this.name} took damage`; | ||
| }; | ||
|
|
||
|
|
||
| /* | ||
| === Humanoid (Having an appearance or character resembling that of a human.) === | ||
|
|
@@ -32,7 +49,17 @@ | |
| * should inherit destroy() from GameObject through CharacterStats | ||
| * should inherit takeDamage() from CharacterStats | ||
| */ | ||
|
|
||
| function Humanoid(human){ | ||
| CharacterStats.call(this, human); | ||
| this.team = human.team; | ||
| this.weapons = human.weapons; | ||
| this.language = human.language; | ||
| } | ||
| Humanoid.prototype = Object.create(CharacterStats.prototype); | ||
| Humanoid.prototype.greet = function(greeting){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you have a greeting parameter but never called it? Maybe it could have just been left out? |
||
| console.log(`${this.name} says hello in ${this.language}`); | ||
| return `${this.name} says hello in ${this.language}`; | ||
| } | ||
| /* | ||
| * Inheritance chain: GameObject -> CharacterStats -> Humanoid | ||
| * Instances of Humanoid should have all of the same properties as CharacterStats and GameObject. | ||
|
|
@@ -41,7 +68,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: { | ||
|
|
@@ -102,7 +129,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. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,50 @@ | ||
| /* The for principles of "this"; | ||
| * in your own words. explain the four principle for the "this" keyword below. | ||
| * | ||
| * 1. | ||
| * 2. | ||
| * 3. | ||
| * 4. | ||
| * | ||
| * 1. This keyword binds to the global scope of an window/object | ||
| * 2. Implicit binding to the object left of the "." | ||
| * 3. "new" is a keyword used to create a constructer, this will point to that object. | ||
| * 4. Explicit binding makes use of .bind, .call, .apply which .this is defined. | ||
|
|
||
| * write out a code example of each explanation above | ||
| */ | ||
|
|
||
| // Principle 1 | ||
|
|
||
| function stranger(name) { | ||
| console.log(this); | ||
| return name; | ||
| } | ||
| stranger("Ricardo"); | ||
| // code example for Window Binding | ||
|
|
||
| // Principle 2 | ||
|
|
||
| // Principle 2 | ||
| const thisObj = { | ||
| color: 'red', | ||
| startRace: function (name) { | ||
| console.log(`The light is ${this.color}, ${name}`); | ||
| console.log(this); | ||
| } | ||
| }; | ||
| thisObj.startRace('Not Yet!'); | ||
| // code example for Implicit Binding | ||
|
|
||
| // Principle 3 | ||
|
|
||
| function Fighter(name) { | ||
| this.arms = '22 inch arms'; | ||
| this.height = '6ft tall'; | ||
| this.stats = function () { | ||
| console.log(this.arms + " " + this.height); | ||
| console.log(this); | ||
| }; | ||
| } | ||
| const Tyson = new Fighter('Mike Tyson'); | ||
| const Holifield = new Fighter('Evander Holyfield'); | ||
| Tyson.stats(); | ||
| Holifield.stats(); | ||
| // code example for New Binding | ||
|
|
||
| // Principle 4 | ||
|
|
||
| Holifield.stats.call(Tyson); | ||
| Tyson.stats.apply(Holifield); | ||
| // code example for Explicit Binding |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love seeing that you are checking your work before you return it. Shows that you care about quality.