ÿþf u n c t i o n   g e t X m l I n s t a n c e ( )  
 {  
       v a r   r e t v a l = n u l l ;  
       t r y  
       {  
             r e t v a l = n e w   A c t i v e X O b j e c t ( " M s x m l 2 . X M L H T T P " ) ;  
       }  
       c a t c h ( e )  
       {  
             t r y  
             {  
                 r e t v a l = n e w   A c t i v e X O b j e c t ( " M i c r o s o f t . X M L H T T P " ) ;  
             }    
             c a t c h ( o c )  
             {  
                 r e t v a l = n u l l ;  
             }  
     }  
     i f ( ! r e t v a l   & &   t y p e o f   X M L H t t p R e q u e s t   ! =   " u n d e f i n e d " )    
     {  
           r e t v a l = n e w   X M L H t t p R e q u e s t ( ) ;  
     }  
   r e t u r n   r e t v a l ;  
 }  
 f u n c t i o n   G e t R e s u l t ( p a r U r l , p a r C o m b o , p a r C o m b o T o F i l l )  
 {  
         / / c r e a t e X H R ( ) ;  
         v a r   t h e _ o b j e c t ;  
         v a r   h t t p _ r e q u e s t   =   g e t X m l I n s t a n c e ( ) ;  
          
         h t t p _ r e q u e s t . o p e n (   " G E T " ,   p a r U r l + p a r C o m b o . v a l u e ,   t r u e   ) ;  
         c l e a r C o m b o ( p a r C o m b o T o F i l l ) ;  
         p a r C o m b o T o F i l l . o p t i o n s [ 0 ] =   n e w   O p t i o n ( " Y ü k l e n i y o r . . . " , " 0 " ) ;  
         h t t p _ r e q u e s t . o n r e a d y s t a t e c h a n g e   =   f u n c t i o n ( ) {  
         i f   (   h t t p _ r e q u e s t . r e a d y S t a t e   = =   4   )    
         {  
                 i f   (   h t t p _ r e q u e s t . s t a t u s   = =   2 0 0   )    
                 {  
                         t h e _ o b j e c t   =   e v a l (   " ( "   +   h t t p _ r e q u e s t . r e s p o n s e T e x t   +   " ) "   ) ;  
                         F i l l C o m b o ( p a r C o m b o T o F i l l , t h e _ o b j e c t ) ;  
                 }    
                 e l s e    
                         a l e r t (   " T h e r e   w a s   a   p r o b l e m   w i t h   t h e   U R L . "   ) ;  
                 h t t p _ r e q u e s t   =   n u l l ;  
         }  
         } ;  
         i f ( p a r C o m b o . v a l u e   ! =   0 )  
                 h t t p _ r e q u e s t . s e n d ( n u l l ) ;  
         e l s e  
                 p a r C o m b o T o F i l l . o p t i o n s [ 0 ]   =   n e w   O p t i o n ( ' S e c i n i z ' , ' 0 ' ) ;  
 }  
  
 f u n c t i o n   B u l t e n E m a i l i K a y d e t ( p a r E m a i l F i e l d , p a r B a s e )  
 {  
         i f (   ! i s V a l i d E m a i l ( p a r E m a i l F i e l d . v a l u e )   )  
         {  
                 d o c u m e n t . g e t E l e m e n t B y I d ( " M e s a j " ) . i n n e r H T M L   =   " L ü t f e n   G e ç e r l i   B i r   E - P o s t a   A d r e s i   G i r i n i z " ;  
                 r e t u r n ;  
         }  
         / / c r e a t e X H R ( ) ;  
         v a r   t h e _ o b j e c t ;  
         v a r   h t t p _ r e q u e s t   =   g e t X m l I n s t a n c e ( ) ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( " M e s a j " ) . i n n e r H T M L   =   " L ü t f e n   B e k l e y i n i z " ;  
         h t t p _ r e q u e s t . o p e n (   " G E T " ,   p a r B a s e + " S e n d F r i e n d H a n d l e r . a s p x ? h C a s e = B u l t e n & E M a i l = " + p a r E m a i l F i e l d . v a l u e ,   t r u e   ) ;  
         h t t p _ r e q u e s t . o n r e a d y s t a t e c h a n g e   =   f u n c t i o n ( ) {  
         i f   (   h t t p _ r e q u e s t . r e a d y S t a t e   = =   4   )    
         {  
                 i f   (   h t t p _ r e q u e s t . s t a t u s   = =   2 0 0   )    
                 {  
                         / / t h e _ o b j e c t   =   e v a l (   " ( "   +   h t t p _ r e q u e s t . r e s p o n s e T e x t   +   " ) "   ) ;  
                         t h e _ o b j e c t   =   h t t p _ r e q u e s t . r e s p o n s e T e x t ;  
                         d o c u m e n t . g e t E l e m e n t B y I d ( " M e s a j " ) . i n n e r H T M L   =   t h e _ o b j e c t ;  
                 }    
                 e l s e    
                         d o c u m e n t . g e t E l e m e n t B y I d ( " M e s a j " ) . i n n e r H T M L   =   " T h e r e   w a s   a   p r o b l e m   w i t h   t h e   U R L . " ;  
                 h t t p _ r e q u e s t   =   n u l l ;  
         }  
         } ;  
           h t t p _ r e q u e s t . s e n d ( n u l l ) ;  
           / / r e t u r n   t r u e ;  
 }  
  
 f u n c t i o n   i s V a l i d E m a i l ( e m a i l )  
 {  
 	 v a r   f i l t e r   =   n e w   R e g E x p ( " ^ ( [ \ \ w - ] + ( ? : \ \ . [ \ \ w - ] + ) * ) @ ( ( ? : [ \ \ w - ] + \ \ . ) * \ \ w [ \ \ w - ] { 0 , 6 6 } ) \ \ . ( [ a - z ] { 2 , 6 } ( ? : \ \ . [ a - z ] { 2 } ) ? ) $ " ,   " i " )  
 	 	 	 	  
 	 i f   ( f i l t e r . t e s t ( e m a i l ) )  
 	 	 r e t u r n   t r u e  
 	 e l s e  
 	 	 r e t u r n   f a l s e  
 }  
  
 f u n c t i o n   c l e a r C o m b o ( s e l )  
 {  
         w h i l e ( s e l . o p t i o n s . l e n g t h )  
                 s e l . r e m o v e ( 0 ) ;  
 }  
 f u n c t i o n   F i l l C o m b o ( p a r C o m b o T o F i l l , p a r D a t a )  
 {  
         p a r C o m b o T o F i l l . o p t i o n s [ 0 ]   =   n e w   O p t i o n ( ' S e c i n i z ' , ' 0 ' ) ;  
         f o r ( i = 0 ; i < p a r D a t a . H e a d . l e n g t h ; i + + )  
         {  
                 p a r C o m b o T o F i l l . o p t i o n s [ i + 1 ]   =   n e w   O p t i o n ( p a r D a t a . H e a d [ i ] . t e x t , p a r D a t a . H e a d [ i ] . v a l u e ) ;  
  
         }  
 }  
 / *  
         j s o n . j s  
         2 0 0 7 - 0 8 - 1 9  
  
         P u b l i c   D o m a i n  
  
         T h i s   f i l e   a d d s   t h e s e   m e t h o d s   t o   J a v a S c r i p t :  
  
                 a r r a y . t o J S O N S t r i n g ( w h i t e l i s t )  
                 b o o l e a n . t o J S O N S t r i n g ( )  
                 d a t e . t o J S O N S t r i n g ( )  
                 n u m b e r . t o J S O N S t r i n g ( )  
                 o b j e c t . t o J S O N S t r i n g ( w h i t e l i s t )  
                 s t r i n g . t o J S O N S t r i n g ( )  
                         T h e s e   m e t h o d s   p r o d u c e   a   J S O N   t e x t   f r o m   a   J a v a S c r i p t   v a l u e .  
                         I t   m u s t   n o t   c o n t a i n   a n y   c y c l i c a l   r e f e r e n c e s .   I l l e g a l   v a l u e s  
                         w i l l   b e   e x c l u d e d .  
  
                         T h e   d e f a u l t   c o n v e r s i o n   f o r   d a t e s   i s   t o   a n   I S O   s t r i n g .   Y o u   c a n  
                         a d d   a   t o J S O N S t r i n g   m e t h o d   t o   a n y   d a t e   o b j e c t   t o   g e t   a   d i f f e r e n t  
                         r e p r e s e n t a t i o n .  
  
                         T h e   o b j e c t   a n d   a r r a y   m e t h o d s   c a n   t a k e   a n   o p t i o n a l   w h i t e l i s t  
                         a r g u m e n t .   A   w h i t e l i s t   i s   a n   a r r a y   o f   s t r i n g s .   I f   i t   i s   p r o v i d e d ,  
                         k e y s   i n   o b j e c t s   n o t   f o u n d   i n   t h e   w h i t e l i s t   a r e   e x c l u d e d .  
  
                 s t r i n g . p a r s e J S O N ( f i l t e r )  
                         T h i s   m e t h o d   p a r s e s   a   J S O N   t e x t   t o   p r o d u c e   a n   o b j e c t   o r  
                         a r r a y .   I t   c a n   t h r o w   a   S y n t a x E r r o r   e x c e p t i o n .  
  
                         T h e   o p t i o n a l   f i l t e r   p a r a m e t e r   i s   a   f u n c t i o n   w h i c h   c a n   f i l t e r   a n d  
                         t r a n s f o r m   t h e   r e s u l t s .   I t   r e c e i v e s   e a c h   o f   t h e   k e y s   a n d   v a l u e s ,   a n d  
                         i t s   r e t u r n   v a l u e   i s   u s e d   i n s t e a d   o f   t h e   o r i g i n a l   v a l u e .   I f   i t  
                         r e t u r n s   w h a t   i t   r e c e i v e d ,   t h e n   s t r u c t u r e   i s   n o t   m o d i f i e d .   I f   i t  
                         r e t u r n s   u n d e f i n e d   t h e n   t h e   m e m b e r   i s   d e l e t e d .  
  
                         E x a m p l e :  
  
                         / /   P a r s e   t h e   t e x t .   I f   a   k e y   c o n t a i n s   t h e   s t r i n g   ' d a t e '   t h e n  
                         / /   c o n v e r t   t h e   v a l u e   t o   a   d a t e .  
  
                         m y D a t a   =   t e x t . p a r s e J S O N ( f u n c t i o n   ( k e y ,   v a l u e )   {  
                                 r e t u r n   k e y . i n d e x O f ( ' d a t e ' )   > =   0   ?   n e w   D a t e ( v a l u e )   :   v a l u e ;  
                         } ) ;  
  
         I t   i s   e x p e c t e d   t h a t   t h e s e   m e t h o d s   w i l l   f o r m a l l y   b e c o m e   p a r t   o f   t h e  
         J a v a S c r i p t   P r o g r a m m i n g   L a n g u a g e   i n   t h e   F o u r t h   E d i t i o n   o f   t h e  
         E C M A S c r i p t   s t a n d a r d   i n   2 0 0 8 .  
  
         T h i s   f i l e   w i l l   b r e a k   p r o g r a m s   w i t h   i m p r o p e r   f o r . . i n   l o o p s .   S e e  
         h t t p : / / y u i b l o g . c o m / b l o g / 2 0 0 6 / 0 9 / 2 6 / f o r - i n - i n t r i g u e /  
  
         T h i s   i s   a   r e f e r e n c e   i m p l e m e n t a t i o n .   Y o u   a r e   f r e e   t o   c o p y ,   m o d i f y ,   o r  
         r e d i s t r i b u t e .  
  
         U s e   y o u r   o w n   c o p y .   I t   i s   e x t r e m e l y   u n w i s e   t o   l o a d   u n t r u s t e d   t h i r d   p a r t y  
         c o d e   i n t o   y o u r   p a g e s .  
 * /  
  
 / * j s l i n t   e v i l :   t r u e   * /  
  
 / /   A u g m e n t   t h e   b a s i c   p r o t o t y p e s   i f   t h e y   h a v e   n o t   a l r e a d y   b e e n   a u g m e n t e d .  
  
 i f   ( ! O b j e c t . p r o t o t y p e . t o J S O N S t r i n g )   {  
  
         A r r a y . p r o t o t y p e . t o J S O N S t r i n g   =   f u n c t i o n   ( w )   {  
                 v a r   a   =   [ ] ,           / /   T h e   a r r a y   h o l d i n g   t h e   p a r t i a l   t e x t s .  
                         i ,                     / /   L o o p   c o u n t e r .  
                         l   =   t h i s . l e n g t h ,  
                         v ;                     / /   T h e   v a l u e   t o   b e   s t r i n g i f i e d .  
  
 / /   F o r   e a c h   v a l u e   i n   t h i s   a r r a y . . .  
  
                 f o r   ( i   =   0 ;   i   <   l ;   i   + =   1 )   {  
                         v   =   t h i s [ i ] ;  
                         s w i t c h   ( t y p e o f   v )   {  
                         c a s e   ' o b j e c t ' :  
  
 / /   S e r i a l i z e   a   J a v a S c r i p t   o b j e c t   v a l u e .   I g n o r e   o b j e c t s   t h a t s   l a c k   t h e  
 / /   t o J S O N S t r i n g   m e t h o d .   D u e   t o   a   s p e c i f i c a t i o n   e r r o r   i n   E C M A S c r i p t ,  
 / /   t y p e o f   n u l l   i s   ' o b j e c t ' ,   s o   w a t c h   o u t   f o r   t h a t   c a s e .  
  
                                 i f   ( v )   {  
                                         i f   ( t y p e o f   v . t o J S O N S t r i n g   = = =   ' f u n c t i o n ' )   {  
                                                 a . p u s h ( v . t o J S O N S t r i n g ( w ) ) ;  
                                         }  
                                 }   e l s e   {  
                                         a . p u s h ( ' n u l l ' ) ;  
                                 }  
                                 b r e a k ;  
  
                         c a s e   ' s t r i n g ' :  
                         c a s e   ' n u m b e r ' :  
                         c a s e   ' b o o l e a n ' :  
                                 a . p u s h ( v . t o J S O N S t r i n g ( ) ) ;  
  
 / /   V a l u e s   w i t h o u t   a   J S O N   r e p r e s e n t a t i o n   a r e   i g n o r e d .  
  
                         }  
                 }  
  
 / /   J o i n   a l l   o f   t h e   m e m b e r   t e x t s   t o g e t h e r   a n d   w r a p   t h e m   i n   b r a c k e t s .  
  
                 r e t u r n   ' [ '   +   a . j o i n ( ' , ' )   +   ' ] ' ;  
         } ;  
  
  
         B o o l e a n . p r o t o t y p e . t o J S O N S t r i n g   =   f u n c t i o n   ( )   {  
                 r e t u r n   S t r i n g ( t h i s ) ;  
         } ;  
  
  
         D a t e . p r o t o t y p e . t o J S O N S t r i n g   =   f u n c t i o n   ( )   {  
  
 / /   E v e n t u a l l y ,   t h i s   m e t h o d   w i l l   b e   b a s e d   o n   t h e   d a t e . t o I S O S t r i n g   m e t h o d .  
  
                 f u n c t i o n   f ( n )   {  
  
 / /   F o r m a t   i n t e g e r s   t o   h a v e   a t   l e a s t   t w o   d i g i t s .  
  
                         r e t u r n   n   <   1 0   ?   ' 0 '   +   n   :   n ;  
                 }  
  
                 r e t u r n   ' " '   +   t h i s . g e t U T C F u l l Y e a r ( )   +   ' - '   +  
                                 f ( t h i s . g e t U T C M o n t h ( )   +   1 )     +   ' - '   +  
                                 f ( t h i s . g e t U T C D a t e ( ) )               +   ' T '   +  
                                 f ( t h i s . g e t U T C H o u r s ( ) )             +   ' : '   +  
                                 f ( t h i s . g e t U T C M i n u t e s ( ) )         +   ' : '   +  
                                 f ( t h i s . g e t U T C S e c o n d s ( ) )         +   ' Z " ' ;  
         } ;  
  
  
         N u m b e r . p r o t o t y p e . t o J S O N S t r i n g   =   f u n c t i o n   ( )   {  
  
 / /   J S O N   n u m b e r s   m u s t   b e   f i n i t e .   E n c o d e   n o n - f i n i t e   n u m b e r s   a s   n u l l .  
  
                 r e t u r n   i s F i n i t e ( t h i s )   ?   S t r i n g ( t h i s )   :   ' n u l l ' ;  
         } ;  
  
  
         O b j e c t . p r o t o t y p e . t o J S O N S t r i n g   =   f u n c t i o n   ( w )   {  
                 v a r   a   =   [ ] ,           / /   T h e   a r r a y   h o l d i n g   t h e   p a r t i a l   t e x t s .  
                         k ,                     / /   T h e   c u r r e n t   k e y .  
                         i ,                     / /   T h e   l o o p   c o u n t e r .  
                         v ;                     / /   T h e   c u r r e n t   v a l u e .  
  
 / /   I f   a   w h i t e l i s t   ( a r r a y   o f   k e y s )   i s   p r o v i d e d ,   u s e   i t   a s s e m b l e   t h e   c o m p o n e n t s  
 / /   o f   t h e   o b j e c t .  
  
                 i f   ( w )   {  
                         f o r   ( i   =   0 ;   i   <   w . l e n g t h ;   i   + =   1 )   {  
                                 k   =   w [ i ] ;  
                                 i f   ( t y p e o f   k   = = =   ' s t r i n g ' )   {  
                                         v   =   t h i s [ k ] ;  
                                         s w i t c h   ( t y p e o f   v )   {  
                                         c a s e   ' o b j e c t ' :  
  
 / /   S e r i a l i z e   a   J a v a S c r i p t   o b j e c t   v a l u e .   I g n o r e   o b j e c t s   t h a t   l a c k   t h e  
 / /   t o J S O N S t r i n g   m e t h o d .   D u e   t o   a   s p e c i f i c a t i o n   e r r o r   i n   E C M A S c r i p t ,  
 / /   t y p e o f   n u l l   i s   ' o b j e c t ' ,   s o   w a t c h   o u t   f o r   t h a t   c a s e .  
  
                                                 i f   ( v )   {  
                                                         i f   ( t y p e o f   v . t o J S O N S t r i n g   = = =   ' f u n c t i o n ' )   {  
                                                                 a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : '   +  
                                                                               v . t o J S O N S t r i n g ( w ) ) ;  
                                                         }  
                                                 }   e l s e   {  
                                                         a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : n u l l ' ) ;  
                                                 }  
                                                 b r e a k ;  
  
                                         c a s e   ' s t r i n g ' :  
                                         c a s e   ' n u m b e r ' :  
                                         c a s e   ' b o o l e a n ' :  
                                                 a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : '   +   v . t o J S O N S t r i n g ( ) ) ;  
  
 / /   V a l u e s   w i t h o u t   a   J S O N   r e p r e s e n t a t i o n   a r e   i g n o r e d .  
  
                                         }  
                                 }  
                         }  
                 }   e l s e   {  
  
 / /   I t e r a t e   t h r o u g h   a l l   o f   t h e   k e y s   i n   t h e   o b j e c t ,   i g n o r i n g   t h e   p r o t o   c h a i n  
 / /   a n d   k e y s   t h a t   a r e   n o t   s t r i n g s .  
  
                         f o r   ( k   i n   t h i s )   {  
                                 i f   ( t y p e o f   k   = = =   ' s t r i n g '   & &  
                                                 O b j e c t . p r o t o t y p e . h a s O w n P r o p e r t y . a p p l y ( t h i s ,   [ k ] ) )   {  
                                         v   =   t h i s [ k ] ;  
                                         s w i t c h   ( t y p e o f   v )   {  
                                         c a s e   ' o b j e c t ' :  
  
 / /   S e r i a l i z e   a   J a v a S c r i p t   o b j e c t   v a l u e .   I g n o r e   o b j e c t s   t h a t   l a c k   t h e  
 / /   t o J S O N S t r i n g   m e t h o d .   D u e   t o   a   s p e c i f i c a t i o n   e r r o r   i n   E C M A S c r i p t ,  
 / /   t y p e o f   n u l l   i s   ' o b j e c t ' ,   s o   w a t c h   o u t   f o r   t h a t   c a s e .  
  
                                                 i f   ( v )   {  
                                                         i f   ( t y p e o f   v . t o J S O N S t r i n g   = = =   ' f u n c t i o n ' )   {  
                                                                 a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : '   +  
                                                                               v . t o J S O N S t r i n g ( ) ) ;  
                                                         }  
                                                 }   e l s e   {  
                                                         a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : n u l l ' ) ;  
                                                 }  
                                                 b r e a k ;  
  
                                         c a s e   ' s t r i n g ' :  
                                         c a s e   ' n u m b e r ' :  
                                         c a s e   ' b o o l e a n ' :  
                                                 a . p u s h ( k . t o J S O N S t r i n g ( )   +   ' : '   +   v . t o J S O N S t r i n g ( ) ) ;  
  
 / /   V a l u e s   w i t h o u t   a   J S O N   r e p r e s e n t a t i o n   a r e   i g n o r e d .  
  
                                         }  
                                 }  
                         }  
                 }  
  
 / /   J o i n   a l l   o f   t h e   m e m b e r   t e x t s   t o g e t h e r   a n d   w r a p   t h e m   i n   b r a c e s .  
  
                 r e t u r n   ' { '   +   a . j o i n ( ' , ' )   +   ' } ' ;  
         } ;  
  
  
         ( f u n c t i o n   ( s )   {  
  
 / /   A u g m e n t   S t r i n g . p r o t o t y p e .   W e   d o   t h i s   i n   a n   i m m e d i a t e   a n o n y m o u s   f u n c t i o n   t o  
 / /   a v o i d   d e f i n i n g   g l o b a l   v a r i a b l e s .  
  
 / /   m   i s   a   t a b l e   o f   c h a r a c t e r   s u b s t i t u t i o n s .  
  
                 v a r   m   =   {  
                         ' \ b ' :   ' \ \ b ' ,  
                         ' \ t ' :   ' \ \ t ' ,  
                         ' \ n ' :   ' \ \ n ' ,  
                         ' \ f ' :   ' \ \ f ' ,  
                         ' \ r ' :   ' \ \ r ' ,  
                         ' " '   :   ' \ \ " ' ,  
                         ' \ \ ' :   ' \ \ \ \ '  
                 } ;  
  
  
                 s . p a r s e J S O N   =   f u n c t i o n   ( f i l t e r )   {  
                         v a r   j ;  
  
                         f u n c t i o n   w a l k ( k ,   v )   {  
                                 v a r   i ;  
                                 i f   ( v   & &   t y p e o f   v   = = =   ' o b j e c t ' )   {  
                                         f o r   ( i   i n   v )   {  
                                                 i f   ( O b j e c t . p r o t o t y p e . h a s O w n P r o p e r t y . a p p l y ( v ,   [ i ] ) )   {  
                                                         v [ i ]   =   w a l k ( i ,   v [ i ] ) ;  
                                                 }  
                                         }  
                                 }  
                                 r e t u r n   f i l t e r ( k ,   v ) ;  
                         }  
  
  
 / /   P a r s i n g   h a p p e n s   i n   t h r e e   s t a g e s .   I n   t h e   f i r s t   s t a g e ,   w e   r u n   t h e   t e x t   a g a i n s t  
 / /   a   r e g u l a r   e x p r e s s i o n   w h i c h   l o o k s   f o r   n o n - J S O N   c h a r a c t e r s .   W e   a r e   e s p e c i a l l y  
 / /   c o n c e r n e d   w i t h   ' ( ) '   a n d   ' n e w '   b e c a u s e   t h e y   c a n   c a u s e   i n v o c a t i o n ,   a n d   ' = '  
 / /   b e c a u s e   i t   c a n   c a u s e   m u t a t i o n .   B u t   j u s t   t o   b e   s a f e ,   w e   w i l l   r e j e c t   a l l  
 / /   u n e x p e c t e d   c h a r a c t e r s .  
  
 / /   W e   s p l i t   t h e   f i r s t   s t a g e   i n t o   3   r e g e x p   o p e r a t i o n s   i n   o r d e r   t o   w o r k   a r o u n d  
 / /   c r i p p l i n g   d e f i c i e n c i e s   i n   S a f a r i ' s   r e g e x p   e n g i n e .   F i r s t   w e   r e p l a c e   a l l  
 / /   b a c k s l a s h   p a i r s   w i t h   ' @ '   ( a   n o n - J S O N   c h a r a c t e r ) .   S e c o n d   w e   d e l e t e   a l l   o f  
 / /   t h e   s t r i n g   l i t e r a l s .   T h i r d ,   w e   l o o k   t o   s e e   i f   o n l y   J S O N   c h a r a c t e r s  
 / /   r e m a i n .   I f   s o ,   t h e n   t h e   t e x t   i s   s a f e   f o r   e v a l .  
  
                         i f   ( / ^ [ , : { } \ [ \ ] 0 - 9 . \ - + E a e f l n r - u   \ n \ r \ t ] * $ / . t e s t ( t h i s .  
                                         r e p l a c e ( / \ \ . / g ,   ' @ ' ) .  
                                         r e p l a c e ( / " [ ^ " \ \ \ n \ r ] * " / g ,   ' ' ) ) )   {  
  
 / /   I n   t h e   s e c o n d   s t a g e   w e   u s e   t h e   e v a l   f u n c t i o n   t o   c o m p i l e   t h e   t e x t   i n t o   a  
 / /   J a v a S c r i p t   s t r u c t u r e .   T h e   ' { '   o p e r a t o r   i s   s u b j e c t   t o   a   s y n t a c t i c   a m b i g u i t y  
 / /   i n   J a v a S c r i p t :   i t   c a n   b e g i n   a   b l o c k   o r   a n   o b j e c t   l i t e r a l .   W e   w r a p   t h e   t e x t  
 / /   i n   p a r e n s   t o   e l i m i n a t e   t h e   a m b i g u i t y .  
  
                                 j   =   e v a l ( ' ( '   +   t h i s   +   ' ) ' ) ;  
  
 / /   I n   t h e   o p t i o n a l   t h i r d   s t a g e ,   w e   r e c u r s i v e l y   w a l k   t h e   n e w   s t r u c t u r e ,   p a s s i n g  
 / /   e a c h   n a m e / v a l u e   p a i r   t o   a   f i l t e r   f u n c t i o n   f o r   p o s s i b l e   t r a n s f o r m a t i o n .  
  
                                 r e t u r n   t y p e o f   f i l t e r   = = =   ' f u n c t i o n '   ?   w a l k ( ' ' ,   j )   :   j ;  
                         }  
  
 / /   I f   t h e   t e x t   i s   n o t   J S O N   p a r s e a b l e ,   t h e n   a   S y n t a x E r r o r   i s   t h r o w n .  
  
                         t h r o w   n e w   S y n t a x E r r o r ( ' p a r s e J S O N ' ) ;  
                 } ;  
  
  
                 s . t o J S O N S t r i n g   =   f u n c t i o n   ( )   {  
  
 / /   I f   t h e   s t r i n g   c o n t a i n s   n o   c o n t r o l   c h a r a c t e r s ,   n o   q u o t e   c h a r a c t e r s ,   a n d   n o  
 / /   b a c k s l a s h   c h a r a c t e r s ,   t h e n   w e   c a n   s i m p l y   s l a p   s o m e   q u o t e s   a r o u n d   i t .  
 / /   O t h e r w i s e   w e   m u s t   a l s o   r e p l a c e   t h e   o f f e n d i n g   c h a r a c t e r s   w i t h   s a f e  
 / /   s e q u e n c e s .  
  
                         i f   ( / [ " \ \ \ x 0 0 - \ x 1 f ] / . t e s t ( t h i s ) )   {  
                                 r e t u r n   ' " '   +   t h i s . r e p l a c e ( / [ \ x 0 0 - \ x 1 f \ \ " ] / g ,   f u n c t i o n   ( a )   {  
                                         v a r   c   =   m [ a ] ;  
                                         i f   ( c )   {  
                                                 r e t u r n   c ;  
                                         }  
                                         c   =   a . c h a r C o d e A t ( ) ;  
                                         r e t u r n   ' \ \ u 0 0 '   +  
                                                 M a t h . f l o o r ( c   /   1 6 ) . t o S t r i n g ( 1 6 )   +  
                                                 ( c   %   1 6 ) . t o S t r i n g ( 1 6 ) ;  
                                 } )   +   ' " ' ;  
                         }  
                         r e t u r n   ' " '   +   t h i s   +   ' " ' ;  
                 } ;  
         } ) ( S t r i n g . p r o t o t y p e ) ;  
 } 
