File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 99var EventEmitter = function ( events ) {
1010 var that = this ;
1111 that . _events = events || [ ] ;
12+ that . _listeners = { } ;
1213} ;
1314EventEmitter . prototype . emit = function ( type ) {
1415 var that = this ;
@@ -19,7 +20,24 @@ EventEmitter.prototype.emit = function(type) {
1920 if ( that [ 'on' + type ] ) {
2021 that [ 'on' + type ] . apply ( that , args ) ;
2122 }
23+ if ( type in that . _listeners ) {
24+ for ( var i = 0 ; i < that . _listeners [ type ] . length ; i ++ ) {
25+ that . _listeners [ type ] [ i ] . apply ( that , args ) ;
26+ }
27+ }
2228} ;
29+
30+ EventEmitter . prototype . on = function ( type , callback ) {
31+ var that = this ;
32+ that . _verifyType ( type ) ;
33+ if ( that . _nuked ) return ;
34+
35+ if ( ! ( type in that . _listeners ) ) {
36+ that . _listeners [ type ] = [ ] ;
37+ }
38+ that . _listeners [ type ] . push ( callback ) ;
39+ } ;
40+
2341EventEmitter . prototype . _verifyType = function ( type ) {
2442 var that = this ;
2543 if ( utils . arrIndexOf ( that . _events , type ) === - 1 ) {
@@ -35,4 +53,5 @@ EventEmitter.prototype.nuke = function() {
3553 for ( var i = 0 ; i < that . _events . length ; i ++ ) {
3654 delete that [ that . _events [ i ] ] ;
3755 }
56+ that . _listeners = { } ;
3857} ;
You can’t perform that action at this time.
0 commit comments