Created
June 9, 2019 18:44
-
-
Save fortunee/3a21b226f244731473dd45576919d3cc to your computer and use it in GitHub Desktop.
The fifth rule of javascript this keyword
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
// Rule #5 example | |
function RuleFive() { | |
this.value = 'Some value for rule #5'; | |
this.printValue = function() { | |
console.log('Rule five value >>>>', this.value); | |
} | |
} | |
const ruleFiveInstance = new RuleFive(); | |
/** | |
* Rule #2 call method takes precedence here | |
* even though dot notation of rule #3 applies | |
*/ | |
ruleFiveInstance.printValue.call({ value: 'Another bounded val'}); | |
// Rule #1 new keyword takes precedence even tho rule #3 applies | |
new ruleFiveInstance.printValue(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment