I could use another eval to get the local definition, but the identifiers have
to be different. Which means I could change the global identifier a bit (prefix
something like '_') and then remember to prepend the prefix whenever the search
was invoked. I don't like that.
Putting the search's main function in a global dictionary make sense. Something
like this...
// evaluate the script at startup
searchFunctions = new Object();
function prepareSearchScripts()
{
eval( "function heydude(q) { WScript.Echo(q) }" );
searchFunctions[ "heydude" ] = eval( "heydude" );
}
prepareSearchScripts();
// invoke the function
searchFunctions[ "heydude" ]( 'greetings sir' );
Searches may be counting on some secondary functions (those not defined in the
<search/> function attribute) which are defined in separate <script/> tags to be
global. I'm not sure how common this is, but it would be necessary because some
of the add-ons use a common .js file to define global functions. In order for
these searches to continue to work, the functions would have to be made global
by assigning a global reference to them. It would require they do something
like this:
bookmarks_get_file = function _bookmarks_get_file(filename)
{
...
}
I don't think this is big deal though. One thing I had experimented with was
using a regex replacement on the string to add this global identifier for each
function. It worked for the most part, but it took me a while to restrict the
regex enough in order to avoid replacing strings that didn't need to be
replaced, and I'm sure it would run into something it couldn't handle sooner or
later.
The other minor change that would be required in some searches has to do with
global variables. Variables declared with 'var' that were expected to be in the
global namespace would have to drop the 'var' with this change.
More thoughts, anyone?
----- Original Message -----
From: "David Bau" <[EMAIL PROTECTED]>
To: "Glenn Carr" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, October 07, 2002 11:29 AM
Subject: [DQSD-Devel] Re: question
> Since you know the name of the function, since it's also in the .xml file,
> could you use another eval to get the local definition, and then assign it
> to the appropriate global (maybe via eval again, or maybe it should go into
> a dictionary object instead of a global variable), without modifying all the
> .xml files?
>
> David
> ----- Original Message -----
> From: "Glenn Carr" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, October 07, 2002 10:56 AM
> Subject: question
>
>
> > I've run into a hitch while trying to move all the core script into
> functions
> > [1]. The problem is where the 'eval' function puts the results when
> evaluating
> > functions. When they are done at global scope (as they are currently),
> the
> > functions are accessible in the global namespace. When the eval is
> performed in
> > a function, the resulting functions are not visible globally.
> >
> > The solution I've come up so far is to parse the script as it is read in,
> and
> > modify the functions as such:
> >
> > gg = function _gg(...)
> > { ... }
> >
> > This assigns a global variable (gg) to the local function, which allows
> the
> > local function to be referenced globally.
> >
> > In more ideas out there?
> >
> > Glenn
> >
> >
> >
> > [1] I'm moving the global code into function in order to be able to
> > control/delay when the actual work is done when starting up the toolbar.
> > Currently, a lot of script is executed when it is loaded simply because
> its
> > scope is global.
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
DQSD-Devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dqsd-devel