Skip to content

Instantly share code, notes, and snippets.

@fortunee
Created June 9, 2019 18:46
Show Gist options
  • Save fortunee/c6f1923081e04d4abe3c652116659abf to your computer and use it in GitHub Desktop.
Save fortunee/c6f1923081e04d4abe3c652116659abf to your computer and use it in GitHub Desktop.
The sixth rule of javascript this keyword example
// Rule #6 example (arrow functions)
function RuleSix() {
this.value = 'Some value for rule #6';
this.printValue = () => {
console.log('Rule six value >>>>', this.value);
}
}
const ruleSix = new RuleSix();
const printRuleSixVal = ruleSix.printValue;
// the this of parent scope is still in use unlike in RuleThree eg
printRuleSixVal();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment