Created
August 20, 2019 19:56
-
-
Save W-Mills/b2ff8572aa5bee9cb791f7317d90282f to your computer and use it in GitHub Desktop.
Clarifying this in javascript example 1
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
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 is the direct-parent foo object context | |
}, | |
}; | |
foo.getBar() // logs 'baz' | |
const qux = foo.getBar; // assigning the function stored as the method getBar to the variable qux in the global scope | |
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