-
Notifications
You must be signed in to change notification settings - Fork 2.3k
javascript iii - prototype and this #331
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
omaddoc
wants to merge
3
commits into
bloominstituteoftechnology:master
Choose a base branch
from
omaddoc:master
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
3 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
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,10 +1,22 @@ | ||
| /* The for principles of "this"; | ||
| /* The four principles of "this"; | ||
| * in your own words. explain the four principle for the "this" keyword below. | ||
| * | ||
| * 1. | ||
| * 2. | ||
| * 3. | ||
| * 4. | ||
| * 1. Window/Global Onject Binding | ||
| After writing an object, | ||
|
|
||
| * 2. Implcit Binding | ||
| when a function is invoked, whatever is to the left of the | ||
| dot, is what the keyword will be referencing | ||
| * | ||
| 3. New Binding | ||
| making a main constructor and then using that to make new objects | ||
|
|
||
|
|
||
| * 4. Explicit Binding | ||
| .call, .apply | ||
| .call uses the .call method to reference 'this' then individually calls one array at a time starting with index 0 | ||
| while apply does the same thing, but just needs a array name to reference all arrays | ||
| also bind is to lock something together in a new function to save and use for later | ||
| * | ||
| * write out a code example of each explanation above | ||
| */ | ||
|
|
@@ -13,14 +25,55 @@ | |
|
|
||
| // code example for Window Binding | ||
|
|
||
| const info = { | ||
| 'name': this.name | ||
| }; | ||
| console.log(info.name) | ||
|
|
||
|
|
||
| // Principle 2 | ||
|
|
||
| // code example for Implicit Binding | ||
|
|
||
| const info = { | ||
| 'name': "Actaeon", | ||
| }; | ||
|
|
||
| info.name | ||
|
|
||
| // Principle 3 | ||
|
|
||
| // code example for New Binding | ||
|
|
||
| const Person = function(name, age, favorite_thing){ | ||
| this.name; | ||
|
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. not quite right on syntax.. this should be: |
||
| this.age; | ||
| this.favorite_thing | ||
| }; | ||
|
|
||
| const the_dude = new Person('Dude', 40, 'white_russian'); | ||
| const dudes_bestfriend = new Person('walter', 45, 'bowling') | ||
| console.log(the_dude); | ||
| console.log(dudes_bestfriend); | ||
|
|
||
| // Principle 4 | ||
|
|
||
| // code example for Explicit Binding | ||
| // code example for Explicit Binding | ||
|
|
||
| const doSomething = function(thing1, thing2, thing3) { | ||
| console.log(this.name, this.age + ' ' + thing1 + ' ' + thing2 + ' ' + thing3) | ||
| } | ||
|
|
||
| const the_dude = { | ||
| 'name': 'lebowski', | ||
| 'age': 40 | ||
| }; | ||
|
|
||
| const thing = ['rug', 'bowling', 'white_russian']; | ||
| // call function | ||
| doSomething.call(the_dude, thing[0], thing[1], thing[2]); | ||
| // apply function | ||
| doSomething.apply(the_dude, thing); | ||
| // bind function | ||
| const savePoint = doSomething.bind(the_dude, thing[0], thing[1], thing[2]); | ||
| savePoint(); | ||
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.
this isn't quite right on implicit binding. Implicit binding is when you call a method on an object, then any
thisin that method are bound to that object