ÿþ/ * *  
   *   T h e   C u s t o m E v e n t   c l a s s   l e t s   y o u   d e f i n e   e v e n t s   f o r   y o u r   a p p l i c a t i o n  
   *   t h a t   c a n   b e   s u b s c r i b e d   t o   b y   o n e   o r   m o r e   i n d e p e n d e n t   c o m p o n e n t .  
   *  
   *   @ p a r a m   { S t r i n g }   t y p e   T h e   t y p e   o f   e v e n t ,   w h i c h   i s   p a s s e d   t o   t h e   c a l l b a c k  
   *                                   w h e n   t h e   e v e n t   f i r e s  
   *   @ p a r a m   { O b j e c t }   o S c o p e   T h e   c o n t e x t   t h e   e v e n t   w i l l   f i r e   f r o m .     " t h i s "   w i l l  
   *                                   r e f e r   t o   t h i s   o b j e c t   i n   t h e   c a l l b a c k .     D e f a u l t   v a l u e :    
   *                                   t h e   w i n d o w   o b j e c t .     T h e   l i s t e n e r   c a n   o v e r r i d e   t h i s .  
   *   @ c o n s t r u c t o r  
   * /  
 E v e n t   =   f u n c t i o n ( t y p e ,   o S c o p e )   {  
         / * *  
           *   T h e   t y p e   o f   e v e n t ,   r e t u r n e d   t o   s u b s c r i b e r s   w h e n   t h e   e v e n t   f i r e s  
           *   @ t y p e   s t r i n g  
           * /  
         t h i s . t y p e   =   t y p e ;  
  
         / * *  
           *   T h e   s c o p e   t h e   t h e   e v e n t   w i l l   f i r e   f r o m   b y   d e f a u l t .     D e f a u l t s   t o   t h e   w i n d o w    
           *   o b j  
           *   @ t y p e   o b j e c t  
           * /  
         t h i s . s c o p e   =   o S c o p e   | |   w i n d o w ;  
  
         / * *  
           *   T h e   s u b s c r i b e r s   t o   t h i s   e v e n t  
           *   @ t y p e   S u b s c r i b e r [ ]  
           * /  
         t h i s . s u b s c r i b e r s   =   [ ] ;  
 } ;  
  
 E v e n t . p r o t o t y p e   =  
 {  
         / * *  
           *   S u b s c r i b e s   t h e   c a l l e r   t o   t h i s   e v e n t  
           *   @ p a r a m   { F u n c t i o n }   f n               T h e   f u n c t i o n   t o   e x e c u t e  
           *   @ p a r a m   { O b j e c t }       o b j             A n   o b j e c t   t o   b e   p a s s e d   a l o n g   w h e n   t h e   e v e n t   f i r e s  
           *   @ p a r a m   { b o o l e a n }     b O v e r r i d e   I f   t r u e ,   t h e   o b j   p a s s e d   i n   b e c o m e s   t h e   e x e c u t i o n  
           *                                                         s c o p e   o f   t h e   l i s t e n e r  
           * /  
 	 s u b s c r i b e :   f u n c t i o n ( f n ,   o b j ,   b O v e r r i d e )  
 	 {  
                 t h i s . s u b s c r i b e r s . p u s h ( n e w   S u b s c r i b e r ( f n ,   o b j ,   b O v e r r i d e ) ) ;  
 	 } ,  
  
         / * *  
           *   U n s u b s c r i b e s   t h e   c a l l e r   f r o m   t h i s   e v e n t  
           *   @ p a r a m   { F u n c t i o n }   f n     T h e   f u n c t i o n   t o   e x e c u t e  
           *   @ p a r a m   { O b j e c t }       o b j   A n   o b j e c t   t o   b e   p a s s e d   a l o n g   w h e n   t h e   e v e n t   f i r e s  
           *   @ r e t u r n   { b o o l e a n }   T r u e   i f   t h e   s u b s c r i b e r   w a s   f o u n d   a n d   d e t a c h e d .  
           * /  
 	 u n s u b s c r i b e :   f u n c t i o n ( f n ,   o b j )  
 	 {  
                 v a r   f o u n d   =   f a l s e ;  
                  
                 f o r   ( v a r   i = 0 ,   l e n = t h i s . s u b s c r i b e r s . l e n g t h ;   i < l e n ;   + + i )  
 	 	 {  
 	 	 	 v a r   s   =   t h i s . s u b s c r i b e r s [ i ] ;  
 	 	 	  
                         i f   ( s   & &   s . c o n t a i n s ( f n ,   o b j ) )  
 	 	 	 {  
                                 t h i s . _ d e l e t e ( i ) ;  
                                  
                                 f o u n d   =   t r u e ;  
                         }  
                 }  
  
                 r e t u r n   f o u n d ;  
 	 } ,  
  
         / * *  
           *   N o t i f i e s   t h e   s u b s c r i b e r s .     T h e   c a l l b a c k   f u n c t i o n s   w i l l   b e   e x e c u t e d  
           *   f r o m   t h e   s c o p e   s p e c i f i e d   w h e n   t h e   e v e n t   w a s   c r e a t e d ,   a n d   w i t h   t h e   f o l l o w i n g  
           *   p a r a m e t e r s :  
           *       < p r e >  
           *       -   T h e   t y p e   o f   e v e n t  
           *       -   A l l   o f   t h e   a r g u m e n t s   f i r e ( )   w a s   e x e c u t e d   w i t h   a s   a n   a r r a y  
           *       -   T h e   c u s t o m   o b j e c t   ( i f   a n y )   t h a t   w a s   p a s s e d   i n t o   t h e   s u b s c r i b e ( )   m e t h o d  
           *       < / p r e >  
           *        
           *   @ p a r a m   { A r r a y }   a n   a r b i t r a r y   s e t   o f   p a r a m e t e r s   t o   p a s s   t o   t h e   h a n d l e r  
           * /  
         f i r e :   f u n c t i o n ( )  
 	 {  
                 f o r   ( v a r   i = 0 ,   l e n = t h i s . s u b s c r i b e r s . l e n g t h ;   i < l e n ;   + + i )  
                 {  
                         v a r   s   =   t h i s . s u b s c r i b e r s [ i ] ;  
                          
                         i f   ( s )  
                         {  
                                 v a r   s c o p e   =   ( s . o v e r r i d e )   ?   s . o b j   :   t h i s . s c o p e ;  
  
                                 s . f n . c a l l ( s c o p e ,   t h i s . t y p e ,   a r g u m e n t s ,   s . o b j ) ;  
                         }  
                 }  
         } ,  
  
         / * *  
           *   R e m o v e s   a l l   l i s t e n e r s  
           * /  
         u n s u b s c r i b e A l l :   f u n c t i o n ( )  
         {  
                 f o r   ( v a r   i = 0 ,   l e n = t h i s . s u b s c r i b e r s . l e n g t h ;   i < l e n ;   + + i )  
                 {  
                         t h i s . _ d e l e t e ( i ) ;  
                 }  
         } ,  
  
         / * *  
           *   @ p r i v a t e  
           * /  
         _ d e l e t e :   f u n c t i o n ( i n d e x )  
         {  
                 v a r   s   =   t h i s . s u b s c r i b e r s [ i n d e x ] ;  
                  
                 i f   ( s )  
                 {  
                         d e l e t e   s . f n ;  
                          
                         d e l e t e   s . o b j ;  
                 }  
  
                 d e l e t e   t h i s . s u b s c r i b e r s [ i n d e x ] ;  
         }  
 } ;  
  
 / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /  
  
 / * *  
   *   @ c l a s s   S t o r e s   t h e   s u b s c r i b e r   i n f o r m a t i o n   t o   b e   u s e d   w h e n   t h e   e v e n t   f i r e s .  
   *   @ p a r a m   { F u n c t i o n }   f n               T h e   f u n c t i o n   t o   e x e c u t e  
   *   @ p a r a m   { O b j e c t }       o b j             A n   o b j e c t   t o   b e   p a s s e d   a l o n g   w h e n   t h e   e v e n t   f i r e s  
   *   @ p a r a m   { b o o l e a n }     b O v e r r i d e   I f   t r u e ,   t h e   o b j   p a s s e d   i n   b e c o m e s   t h e   e x e c u t i o n  
   *                                                         s c o p e   o f   t h e   l i s t e n e r  
   *   @ c o n s t r u c t o r  
   * /  
 S u b s c r i b e r   =   f u n c t i o n ( f n ,   o b j ,   b O v e r r i d e )  
 {  
         / * *  
           *   T h e   c a l l b a c k   t h a t   w i l l   b e   e x e c u t e   w h e n   t h e   e v e n t   f i r e s  
           *   @ t y p e   f u n c t i o n  
           * /  
         t h i s . f n   =   f n ;  
  
         / * *  
           *   A n   o p t i o n a l   c u s t o m   o b j e c t   t h a t   w i l l   p a s s e d   t o   t h e   c a l l b a c k   w h e n  
           *   t h e   e v e n t   f i r e s  
           *   @ t y p e   o b j e c t  
           * /  
         t h i s . o b j   =   o b j   | |   n u l l ;  
  
         / * *  
           *   T h e   d e f a u l t   e x e c u t i o n   s c o p e   f o r   t h e   e v e n t   l i s t e n e r   i s   d e f i n e d   w h e n   t h e  
           *   e v e n t   i s   c r e a t e d   ( u s u a l l y   t h e   o b j e c t   w h i c h   c o n t a i n s   t h e   e v e n t ) .  
           *   B y   s e t t i n g   o v e r r i d e   t o   t r u e ,   t h e   e x e c u t i o n   s c o p e   b e c o m e s   t h e   c u s t o m  
           *   o b j e c t   p a s s e d   i n   b y   t h e   s u b s c r i b e r  
           *   @ t y p e   b o o l e a n  
           * /  
         t h i s . o v e r r i d e   =   ( b O v e r r i d e ) ;  
 } ;  
  
 / * *  
   *   R e t u r n s   t r u e   i f   t h e   f n   a n d   o b j   m a t c h   t h i s   o b j e c t s   p r o p e r t i e s .  
   *   U s e d   b y   t h e   u n s u b s c r i b e   m e t h o d   t o   m a t c h   t h e   r i g h t   s u b s c r i b e r .  
   *  
   *   @ p a r a m   { F u n c t i o n }   f n   t h e   f u n c t i o n   t o   e x e c u t e  
   *   @ p a r a m   { O b j e c t }   o b j   a n   o b j e c t   t o   b e   p a s s e d   a l o n g   w h e n   t h e   e v e n t   f i r e s  
   *   @ r e t u r n   { b o o l e a n }   t r u e   i f   t h e   s u p p l i e d   a r g u m e n t s   m a t c h   t h i s    
   *                                       s u b s c r i b e r ' s   s i g n a t u r e .  
   * /  
 S u b s c r i b e r . p r o t o t y p e . c o n t a i n s   =   f u n c t i o n ( f n ,   o b j )  
 {  
         r e t u r n   ( t h i s . f n   = =   f n   & &   t h i s . o b j   = =   o b j ) ;  
 } ; 
