Skip to content

Instantly share code, notes, and snippets.

@fortunee
Created June 9, 2019 18:35
Show Gist options
  • Save fortunee/b9d2a189f4a2fa2ebb1da010528cbbda to your computer and use it in GitHub Desktop.
Save fortunee/b9d2a189f4a2fa2ebb1da010528cbbda to your computer and use it in GitHub Desktop.
The second rule of javascript this keyword example
// 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