Hello, can someone explain what happens in the line with “bind” (the state.colors returns an array in this example):
const print = compose(
list = console.log(list),
titles = titles.join(", "),
map = map(c=c.title),
colors = colors.map.bind(colors),
state = state.colors
The first argument to bind is the this value. So I assume that the colors is going to be used somewhere else, and needs to retain the value it has in the place it is defined (in that chunk of code above) rather than the place it is called. There is no context to any of the code you posted, so can’t tell you anything specific.
Thanks for the answers.
I’ve edited the original question to show the entire code (github) and it’s result (that can be seen in the devtools console).
After reading your answers and the links, I get the general idea but not how it applies in this specific case. If I understand correctly, the state=>state.colors returns an array, but don’t all arrays have the map method? Also, shouldn’t arrow function solve this problem? Why would you need the bind then (the code doesn’t work without the using bind on the color argument, so probably it has to be very important).
Thanks for your time