Last active
August 20, 2019 22:04
-
-
Save W-Mills/8dc28ef13918b3f22f3f9a248d5169bd to your computer and use it in GitHub Desktop.
Clairifying this in Javascript example 5
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: 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