src/aja.js
function(name, data){
                var self = this;
                var eventCalls  = function eventCalls(name, data){
                    if(events[name] instanceof Array){
                        events[name].forEach(function(event){
                            event.call(self, data);
                        });
                    }
                };
                if(typeof name !== 'undefined'){
                    name = name + '';
                    var statusPattern = /^([0-9])([0-9x])([0-9x])$/i;
                    var triggerStatus = name.match(statusPattern);

                    //HTTP status pattern
                    if(triggerStatus && triggerStatus.length > 3){
                        Object.keys(events).forEach(function(eventName){
                            var listenerStatus = eventName.match(statusPattern);
                            if(listenerStatus && listenerStatus.length > 3 &&       //an listener on status
                                triggerStatus[1] === listenerStatus[1] &&           //hundreds match exactly
                                (listenerStatus[2] === 'x' ||  triggerStatus[2] === listenerStatus[2]) && //tens matches
                                (listenerStatus[3] === 'x' ||  triggerStatus[3] === listenerStatus[3])){ //ones matches

                                eventCalls(eventName, data);
                            }
                        });
                    //or exact matching
                    } else if(events[name]){
                        eventCalls(name, data);
                    }
                }
                return this;
            }
function(name, data){
                var self = this;
                var eventCalls  = function eventCalls(name, data){
                    if(events[name] instanceof Array){
                        events[name].forEach(function(event){
                            event.call(self, data);
                        });
                    }
                };
                if(typeof name !== 'undefined'){
                    name = name + '';
                    var statusPattern = /^([0-9])([0-9x])([0-9x])$/i;
                    var triggerStatus = name.match(statusPattern);

                    //HTTP status pattern
                    if(triggerStatus && triggerStatus.length > 3){
                        Object.keys(events).forEach(function(eventName){
                            var listenerStatus = eventName.match(statusPattern);
                            if(listenerStatus && listenerStatus.length > 3 &&       //an listener on status
                                triggerStatus[1] === listenerStatus[1] &&           //hundreds match exactly
                                (listenerStatus[2] === 'x' ||  triggerStatus[2] === listenerStatus[2]) && //tens matches
                                (listenerStatus[3] === 'x' ||  triggerStatus[3] === listenerStatus[3])){ //ones matches

                                eventCalls(eventName, data);
                            }
                        });
                    //or exact matching
                    } else if(events[name]){
                        eventCalls(name, data);
                    }
                }
                return this;
            }
function ( name , data ) { var self = this ; var eventCalls = function eventCalls ( name , data ) { if ( events [ name ] instanceof Array ) { events [ name ] . forEach ( function ( event ) { event . call ( self , data ) ; } ) ; } } ; if ( typeof name !== 'undefined' ) { name = name + '' ; var statusPattern = / ^([0-9])([0-9x])([0-9x])$ / i ; var triggerStatus = name . match ( statusPattern ) ; //HTTP status pattern if ( triggerStatus && triggerStatus . length > 3 ) { Object . keys ( events ) . forEach ( function ( eventName ) { var listenerStatus = eventName . match ( statusPattern ) ; if ( listenerStatus && listenerStatus . length > 3 && //an listener on status triggerStatus [ 1 ] === listenerStatus [ 1 ] && //hundreds match exactly ( listenerStatus [ 2 ] === 'x' || triggerStatus [ 2 ] === listenerStatus [ 2 ] ) && //tens matches ( listenerStatus [ 3 ] === 'x' || triggerStatus [ 3 ] === listenerStatus [ 3 ] ) ) { //ones matches eventCalls ( eventName , data ) ; } } ) ; //or exact matching } else if ( events [ name ] ) { eventCalls ( name , data ) ; } } return this ; }
Trigger an event.
This method will be called hardly ever outside Aja itself,
but there is edge cases where it can be useful.

@example aja().trigger('error', new Error('Emergency alert'));

@param {String} name - the name of the event to trigger
@param {*} data - arguments given to the handlers
@returns {Aja} chains
Trigger an event . This method will be called hardly ever outside Aja itself but there is edge cases where it can be useful .