JavaScript Mapping for Modules

A Slice module maps to a JavaScript scope with the same name as the Slice module. The mapping preserves the nesting of the Slice definitions. For example:

// Definitions at global scope here...

module M1 {
    // Definitions for M1 here...
    module M2 {
        // Definitions for M2 here...

// ...

module M1 {     // Reopen M1
    // More definitions for M1 here...

This definition maps to the corresponding JavaScript definitions:

(function(module, require, exports)
    var Ice = ...
    var __M = Ice.__M;
    var M1 = __M.module("M1");
    // Definitions for M1 here...
    M1.M2 = __M.module("M1.M2");
    // Definitions for M2 here...
    // More definitions for M1 here...

    exports.M1 = M1;
(typeof (global) !== ...);

The definitions exported by the generated Slice code for top-level modules add symbols to the global window object in browsers, or to the native exports object in NodeJS.

When developing for NodeJS, you include the various Ice components with require statements as shown below:

var Ice = require("ice").Ice;
var IceGrid = require("ice").IceGrid;
var IceStorm = require("ice").IceStorm;

Importing the generated code for your own Slice definitions works the same way:

var M1 = require("M1Defs").M1;

This example assumes the generated Slice definitions are in the file M1Defs.js.

In a browser application, the necessary JavaScript files are usually loaded via HTML:

<script type="text/javascript" src="Ice.js"></script>
<script type="text/javascript" src="M1Defs.js"></script>
<script type="text/javascript">
    // You can now access Ice and M1 as global objects

The file Ice.js shown above only provides definitions for the Ice run time; you would need to explicitly include the corresponding files for any other Ice components that your application needs, such as IceGrid.js.

See Also