For example, if there's multiple lines to be drawn, I could do
function drawLines(lines) {
lines.forEach(function (line) {
drawLine(line);
});
}
function drawLine(line) {
//...
}
and then in the "main" section of the code I would merely have to call drawLines(lines)
rather than writing a forEach
there.
This does prevent the need for multiple forEach
's to be written if there's more than one section of code that needs to render some lines. I'd only need to call drawLines(lines)
in any such place. But at the same time, it just feels like a bit of a silly thing to do.
(The lines thing is just an example... I'm just talking about the general concept of "do something with each item in an array").
lines.forEach(drawLine);