Created
June 9, 2019 18:35
-
-
Save fortunee/b9d2a189f4a2fa2ebb1da010528cbbda to your computer and use it in GitHub Desktop.
The second rule of javascript this keyword example
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 #2 example | |
function RuleTwo() { | |
this.value = 'Some value for rule #2'; | |
this.printValue = function() { | |
console.log('Rule two value >>>>', this.value); | |
} | |
} | |
const ruleTwoInstance = new RuleTwo(); | |
// Original value of 'this' used here | |
ruleTwoInstance.printValue(); | |
// Bounded value is used here | |
ruleTwoInstance.printValue.bind({ value: 'Bound value' })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment