Subj : Re: [rhino] constructing functions from a code snippet To : Brendan Eich From : Igor Bukanov Date : Tue Dec 09 2003 11:47 am Brendan Eich wrote: > Igor Bukanov wrote: > >> Michael Gratton wrote: >> >>> >>> Guys, >>> >>> Is there a better way to construct an instance of Function when you >>> only have the body of the function than what I'm doing currently, >>> which is: >>> >>> function = cxt.compileFunction(scope, >>> "function (arg1) {" + script + "}", >>> ...); >>> >>> This is for executing something like a HTML inline event handler. >>> >> >> You can not do any better then that. Note that for compatibility >> function's argument should be called event, not arg1. > > > > Does compileFunction really expect the function source, not just the > body, as the second arg? I should just read the Rhino sources, but it > surprised me that it didn't constrain its input, take an array of formal > parameter names, etc. > > /be compileFunction in Rhino indeed requires the full function source, the optimization is that it generates bytecode only for the function itself, not for the enclosing script. I do not now why it was done in this way since the first public release of Rhino already contained that code. Regards, Igor .