get instance of load() function in nashorn

377 views Asked by At

How can I go about getting an instance of a script that is loaded in Java Script?

I'm using the function load("script.js") and I need to call a function on that script, but I need the instance in a variable so i can store it in a map.

I need something like var script = load("script.js")

Then I can call script.unload() // a function defined in script.js

1

There are 1 answers

0
T.J. Crowder On

When you load a script, it's executed and any bindings it creates in the environment are created. You cannot unload a script. If you know what all of its bindings and other effects are, you could clear them all (for instance, if loading Underscore, you could do _ = undefined to clear that binding), but it's unlikely that all of the effects of loading the script will be undone.

(This isn't a Nashorn thing, it's a JavaScript thing. There's one environment shared by all loaded scripts. ES2015's modules help organize that better, but there's still just one overall environment.)