videojs/video.js — pull request #1231 by themicp (2014-05-22 15:48:01+00:00)
Title: Register multiple event listeners with the same callback in one call

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:
```
player.on('canplay', vjs.bind(this, this.hide));
player.on('canplaythrough', vjs.bind(this, this.hide));
player.on('playing', vjs.bind(this, this.hide));
player.on('seeking', vjs.bind(this, this.show));
player.on('seeked', vjs.bind(this, this.hide));
player.on('ended', vjs.bind(this, this.hide));
player.on('waiting', vjs.bind(this, this.show));
```

We want to run the function ``vjs.bind(this, this.hide)`` for 5 different events and for that purpose we call ``player.on`` 5 times which makes the code very long and ugly.

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. With this feature the constructor of the Loading Spinner would look like this:
```
player.on(['canplay', 'canplaythrough', 'playing', 'seeked', 'ended' ], vjs.bind(this, this.hide));
player.on(['seeking', 'error', 'waiting'], vjs.bind(this, this.show));
```
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.
I have also included comments, unit tests for all of my changes (including .arrayForEach()) and updated the exports file to export vjs.on, vjs.off and vjs.one to be able to access them using bracket notation from vjs. forwardMultipleEvents.