Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Register multiple event listeners with the same callback in one call #1231
There are cases where you want the same function to be called for many different events. For example take a look at the following code from the constructor of the Loading Spinner:
We want to run the function
From this, I came up with this feature/enhancement where you can call vjs.on with an array of events and attach the callback in all of them with a single call (passing an event as a string still works as before). With this feature the constructor of the Loading Spinner would look like this:
The same goes with vjs.one and vjs.off, too.
For the implementation of this feature I needed a method to run a function for each element of an array but Array.prototype.forEach() was not a good idea due to performance issues (http://jsperf.com/fast-array-foreach) so I created vjs.arrayForEach which does the same thing but using the for() loop.