Last active
August 20, 2019 20:38
-
-
Save W-Mills/1dca6251e1858e84aa03fe089d396437 to your computer and use it in GitHub Desktop.
Clarifying This in JavaScript example 1
This file contains 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
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