Subj : Re: Scoping question To : netscape.public.mozilla.jseng From : r.knight@zoodigitalgroup.com (Rich K) Date : Wed Jan 14 2004 12:40 am Marcello Bastea-Forte wrote in message news:... > > I'd like each of the final two bits of script to be able to use the > > first global function and variable, but only see it's own version of > > MyOtherFunc and Var. I don't want two totally separate sets of script > > - I only want to define and run MyFunc once, since it may do something > > very time consuming. Hope that makes some sense :) > > That way the function is defined directly in the object, and you don't > need to worry about name collisions (or doing something like function > Object1_MyOtherFunc()). > Hi, Bit more complicated than that I think - suspect I explained it badly :) The 'objects' in our application aren't JavaScript objects at all - they're written in C++ and are fairly unrelated. The user can write fragments of JavaScript associated with them to customise the behaviour of various things at various times. So the application structure looks a bit like: Project | |---- Thing 1 | |---- Thing 2 The user can add bits of script to each of these objects, and when customising Thing 1 and Thing 2 may well decide to add functions which share the same name but do different things. I'd like both Thing 1 and Thing 2 to see whatever functions and globals were defined when the script in Project was run, but not whatever is defined in each others script. My first thought was to pass different JSObject* pointers into JC_EvaluateUCScript, one object for Project, another for Thing 1, and another for Thing 2. Only then there's no relation between the 'Thing' objects and the object used when the Project script was defined - so I don't think any of the Project functions and properties will be visible. I'm guessing I'm on the right lines still, but that I need to set up some sort of parent-child association between the JSObject* pointers used when the Thing script was evaluated and the one used when the Project script was evaluated? Hope that makes a bit more sense anyway :) Thanks! Rich. .