Subj : Re: Creating classes/namespaces on the fly from existing functions? To : netscape.public.mozilla.jseng From : Ludovic Delabre Date : Fri Feb 04 2005 07:34 am Brendan Eich wrote: > bubbfree@gmail.com wrote: > >> The object or namespace 'externalFile1' would be dynamically created by >> the useLibrary() implementation, and all functions found in that file >> would be added as member functions of the newly created >> object/namespace. >> >> Is this possible? Thanks! > > > > Sure, it's possible. useLibrary would parse its argument, > JS_DefineObject using the name up to the ".js" and defining the new > object in the global object, and so on. Beware JSOPTION_VAROBJFIX, > however -- you don't want this option for this application. > > (One way to use JSOPTION_VAROBJFIX would be to temporarily > JS_SetParent(cx, libobj, NULL) and JS_SetParent(cx, libobj, global) > around all JS_Evaluate*Script* and JS_Compile* API calls.) > > /be Hi! I'm quite new to spidermonkey's API but... Another way to get around the "assignment to an unbound id" bug would be to use a new context for each file, no ? Thx, Ludovic. .