Helma Logo
main list history
previous version  overview  next version

Version 1 by hannes on 23. May 2008, 12:39

One of the cornerstones of Helma NG, and one that distinguishes it from every other JavaScript runtime out there, is how it handles modules and scopes.

=== Modules

Helma NG handles JavaScript resources as Modules. If this evokes associations to *Python|http://docs.python.org/tut/node8.html* it is fully intentional, because NG Modules work and feel very much like *Python Modules|http://effbot.org/zone/import-confusion.htm*.

First, if one module wants to make use of another module, it needs to import the other module. Helma NG provides two global functions for this, one to import a module into a discrete namespace, and another to import some or all properties of a module into its own scope.

Now the special thing about Helma NG is that the two modules (one doing the import, the other being imported) are fully isolated from each other. The imported module does not have any way at all to access the importing module, and the importing module can only access the imported one via the namespace into which it imported it, or the properties and functions it explicitly imported from it. And what's more, you don't have to do anything special to accomplish this. You just write scripts with global functions and properties and never worry about stuff that is defined in other scripts.

The way Helma NG does this is by giving each Module its own top-level scope.

=== Module Scope

=== importModule()

=== importFromModule()

=== The shared global scope

=== The per-thread global scope