I believe, there is a shorter way (one line) to write this using lodash:
_.forEach(eventListeners, function(callback) {
callback(event);
})
... but can't find yet
I believe, there is a shorter way (one line) to write this using lodash:
_.forEach(eventListeners, function(callback) {
callback(event);
})
... but can't find yet
Lodash provides a utility function called _.over that returns a function that you can then call to pass some arguments to all of the functions you provided to _.over
Official documentation for _.over
var funs = [
function(e) { console.log(e) },
function(e) { console.log(e*2) },
function(e) { console.log(e*3) }
];
_.over(funs)(10);
This will call all of the functions in the funs array with 10 as their argument, so in this case you should see in your console:
10
20
30
In your case specifically:
_.over(eventListeners)(event);