src/event-emitter.js
function (eventName, callback) {
				if (RUNTIME_CHECKS) {
					if (typeof eventName !== 'string') {
						throw '"eventName" argument must be a string';
					}
					if (typeof callback !== 'function') {
						throw '"callback" argument must be a function';
					}
				}

				this.__private || Object.defineProperty(this, '__private', { writable: true, value: {}, });
				var listeners = this.__private.listeners || (this.__private.listeners = {});
				var listenersForEvent = listeners[eventName] || (listeners[eventName] = []);

				if (RUNTIME_CHECKS && listenersForEvent.indexOf(callback) !== -1) {
					throw 'This listener has already been added (event: ' + eventName + ')';
				}

				listenersForEvent.push(callback);
			}
function (eventName, callback) {
				if (RUNTIME_CHECKS) {
					if (typeof eventName !== 'string') {
						throw '"eventName" argument must be a string';
					}
					if (typeof callback !== 'function') {
						throw '"callback" argument must be a function';
					}
				}

				this.__private || Object.defineProperty(this, '__private', { writable: true, value: {}, });
				var listeners = this.__private.listeners || (this.__private.listeners = {});
				var listenersForEvent = listeners[eventName] || (listeners[eventName] = []);

				if (RUNTIME_CHECKS && listenersForEvent.indexOf(callback) !== -1) {
					throw 'This listener has already been added (event: ' + eventName + ')';
				}

				listenersForEvent.push(callback);
			}
function ( eventName , callback ) { if ( RUNTIME_CHECKS ) { if ( typeof eventName !== 'string' ) { throw '"eventName" argument must be a string' ; } if ( typeof callback !== 'function' ) { throw '"callback" argument must be a function' ; } } this . __private || Object . defineProperty ( this , '__private' , { writable : true , value : { } , } ) ; var listeners = this . __private . listeners || ( this . __private . listeners = { } ) ; var listenersForEvent = listeners [ eventName ] || ( listeners [ eventName ] = [ ] ) ; if ( RUNTIME_CHECKS && listenersForEvent . indexOf ( callback ) !== - 1 ) { throw 'This listener has already been added (event: ' + eventName + ')' ; } listenersForEvent . push ( callback ) ; }
Add an event listener function that will be called whenever the given event is emitted. Trying to add the exact same function twice till throw an error, as that is rarely ever the intention and a common source of errors.
@instance
@arg {string} eventName - Identifier string for the event that is to be listened to.
@arg {function} callback - The function that will be called when the event is emitted.
Add an event listener function that will be called whenever the given event is emitted . Trying to add the exact same function twice till throw an error as that is rarely ever the intention and a common source of errors .