As VMG writes, it's one of a few places where 'eval' is the right tool for the job. In this case you either have to drop the feature (of providing replacement function), implement your own language/DSL that compiles down to JS function or just use eval.
What would you do in this case?