3 ms·
Since this is a common occurrence, it might make sense to define a helper function to make it more natural, maybe something like: function only1(f) {
by lgas 12y ago
Since this is a common occurrence, it might make sense to define a helper function to make it more natural, maybe something like:
function only1(f) {
return function(x) {
return f(x);
};
}
then your example becomes:
items.forEach(only1(doSomething));
Edit: just realized this is what "spots" in the blog post bahmutov linked to does (except spots is more flexible).