Subj : Re: SM: JS_ExecuteScript and rval To : Franky Braem From : Brendan Eich Date : Sun Apr 06 2003 03:45 pm Franky Braem wrote: > Hi, > > I read the following in the API-docs > > JS_ExecuteScript executes a previously compiled script, script. On > successful completion, rval is a > pointer to a variable that holds the value from the last executed expression > statement processed in > the script. > > What happens when the script only contains a function? I returns undefined. > Wouldn't it be nice when the function object is returned? > > I want to use this to implement a better way for event handling in wxJS. eg. > > frame.onClose = wxScript("close.js"); This seems wrong: the value returned by wxScript is not the result of evaluating the script in close.js, correct? It's a script object that can be executed later, whose code is compiled from the source in close.js, right? You are removing one level of reference here. I think that makes for problems where users explicitly want a script object, to defer multiple executions and amortize compilation overhead. What if there are several functions in close.js? Why can't I refer to each of them? Why must I break each handler into its own source file? It would be better to require users to say what they mean: frame.onClose = wxScript("close.js").onCloseHandler; You would have to extend wxScript so it could look up functions declared in the compiled script. /be .