Skip to content

Instantly share code, notes, and snippets.

@W-Mills
Last active August 20, 2019 20:47
Show Gist options
  • Save W-Mills/dee060f4d52c84b1263aeb6d61091c9f to your computer and use it in GitHub Desktop.
Save W-Mills/dee060f4d52c84b1263aeb6d61091c9f to your computer and use it in GitHub Desktop.
Clarifying this in JavaScript example 2
const foo = {
bar: 'baz',
getBar: function() {
console.log(this.bar);
},
};
let qux = foo.getBar;
qux.call(foo); // logs 'baz'
qux(); // logs undefined
qux.apply(foo); // logs 'baz'
qux(); // logs undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment