Skip to main content
Skip table of contents

Server-Side JavaScript Mapping for Interfaces

Skeleton Classes

On the server side, interfaces map to skeleton classes. A skeleton is a type that conceptually has an abstract method for each operation on the corresponding interface. For example, consider our Slice definition for the Node interface:

SLICE
module Filesystem
{
    interface Node
    {
        idempotent string name();
    }
    // ...
}

The Slice compiler generates the following definition for this interface:

JS
class Node extends Ice.Object {
    ...
}
TYPESCRIPT
abstract class Node extends Ice.Object {
    abstract name(current:Ice.Current): PromiseLike<string>|string;
}

The important points to note here are:

  • As for the client side, Slice modules are mapped to JavaScript objects with the same name, so the skeleton definitions are part of the Filesystem object.

  • For each Slice interface <interface-name>, the compiler generates a JavaScript class <interface-name> (Node in this example). This type extends Ice.Object and serves as the actual skeleton; it is the base type from which you derive your servant implementation.

Servant Classes

In order to provide an implementation for an Ice object, you must create a servant class that inherits from the corresponding skeleton. For example, to create a servant for the Node interface, you could write:

JS
class MNode extends Filesystem.Node {
    _name:string;
  
    constructor(name:string) {
        this._name = name;
    }

    name(current:Ice.Current) {
        return this._name;
    }
}

Note that MNode extends Filesystem.Node, the skeleton class.

As far as Ice is concerned, the MNode class must implement only a single method: the abstract method name. This makes the servant class a concrete class that you can instantiate. You can add other methods and fields as you see fit to support your implementation. For example, in the preceding definition, we added a _name field and a constructor.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.