Helma Logo
main list history
previous version  overview  next version

Version 3 by hannes on 15. April 2008, 02:20

ScriptCore is an experimental, next-generation script management module for the Rhino Javascript engine. ScriptCore tries to loosely imitate the semantics of python's import statement in order to allow applications to be written in a truly modular way. These are some of the design goals:

* By default, import() loads libraries into a separate scope matching the library's script name.
* The scope name can be overridden by passing a second argument to the import function.
* Never is a library imported into the top level scope.
* If a library is imported into a scope that alreay is defined in the current script's code, the previous value is overwritten.
* Imported libraries are local to the script that imported them (which is possible because the script lives itself in its own scope).
* (If the same library is imported from different scripts within one application (possibly using different scope names), only one version of the library is instanciated and shared among the importing scripts.)?
* Imported libraries are aware of their location so they can use relative path names for local imports and references to other resources.

A simplistic implementation of most of the behaviour described above in Rhino may look like this:

  function include(script, as) {
    var scope = new Object();
    scope.__parent__ = null;
    scope.__proto__ = this;
    this[as] = scope;