Hi all,

If load() is called within a function, is the code thereby loaded
available to the global scope (and hence to the function) or only to
the function's scope (as I would expect)?

Because, I'm loading code (which defines a couple of objects) within a
function, setting a local variable within the function, instantiating
some of the loaded objects within the function, and then finding that
these instantiated objects cannot access the function's local
variable.

For example:

var batman = 'Bruce Wayne';
load('../gotham.js'); // var joker = function() { print(batman); };
new joker();

Returns: ReferenceError: "batman" is not defined.

Whereas:

var batman = 'Bruce Wayne';
eval(readFile('../gotham.js', 'utf-8'));
new joker();

Returns: Bruce Wayne

Your help would be much appreciated. Please excuse me if this is a
simple case of ignorance on my part.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to