Skip to content

Instantly share code, notes, and snippets.

@W-Mills
Last active August 20, 2019 20:38
Show Gist options
  • Save W-Mills/1dca6251e1858e84aa03fe089d396437 to your computer and use it in GitHub Desktop.
Save W-Mills/1dca6251e1858e84aa03fe089d396437 to your computer and use it in GitHub Desktop.
Clarifying This in JavaScript example 1
const foo = {
bar: 'baz',
getBar: function() { // assigned as a property on an object, getBar is a method
console.log(this.bar); // the value of this here: foo
},
};
foo.getBar() // logs 'baz'
let qux = foo.getBar; // assigning the function getBar to the variable qux
qux() // logs undefined, then returns undefined => why?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment