Skip to content

Instantly share code, notes, and snippets.

@W-Mills
Last active August 20, 2019 21:45
Show Gist options
  • Save W-Mills/7e33f1ebdc063e6611d8219e0e071fdd to your computer and use it in GitHub Desktop.
Save W-Mills/7e33f1ebdc063e6611d8219e0e071fdd to your computer and use it in GitHub Desktop.
Clairifying this in Javascript example 4
const foo = {
bar: 10,
multiplyByBar: function(...args) {
args.forEach(function(arg) {
console.log(arg * this.bar);
}, this);
}
};
const qux = foo.multiplyByBar.bind(foo);
foo.bar = 100;
qux(5); // logs 500
qux(5, 10, 15); // logs 500, then 1000, then 1500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment