Do you have a working example?  For some reason, I thought you'd have to evaluate some javascript code (using the javascript eval function) to define a function instead of passing in a string.