Skip to content

Instantly share code, notes, and snippets.

@W-Mills
Last active August 20, 2019 22:04
Show Gist options
  • Save W-Mills/8dc28ef13918b3f22f3f9a248d5169bd to your computer and use it in GitHub Desktop.
Save W-Mills/8dc28ef13918b3f22f3f9a248d5169bd to your computer and use it in GitHub Desktop.
Clairifying this in Javascript example 5
const foo = {
bar: 10,
multiplyByBar: function(...args) {
args.forEach(arg => console.log(arg * this.bar)); // arrow function does not change the context
}
};
const qux = foo.multiplyByBar.bind(foo);
qux(5); // logs 50
qux(5, 10, 15); // logs 50, then 100, then 150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment