question: private static String addMethodstoObject ( final String js ) { final Pattern pat = Pattern . compile ( "function\\s\\w+\\((\\w+)?\\)" ) ; final Matcher mat = pat . matcher ( js ) ; final HashMap < String , String > mapping = new HashMap < String , String > ( ) ; while ( mat . find ( ) ) { final String s = mat . group ( ) ; final String methodSig = js . substring ( mat . start ( ) + 9 , mat . end ( ) ) ; final int firstBracket = methodSig . indexOf ( '(' ) ; final String methodName = methodSig . substring ( 0 , firstBracket ) ; final String newMethodSig = "this." + methodName + " = " + "function" + methodSig . substring ( firstBracket ) ; mapping . put ( s , newMethodSig ) ; } String newJs = js ; for ( final String s : mapping . keySet ( ) ) { newJs = newJs . replace ( s , mapping . get ( s ) ) ; } return newJs ; }
target:  Turns function declarations like function thisIsAFunction(param) {...} into: this.thisIsAFunction = function(param) {...}