WARNING: This server provides a static reference view of the NetKernel documentation. Links to dynamic content do not work. For the best experience we recommend you install NetKernel and view the documentation in the live system .

Library Imports

A Javascript script may import other scripts as libraries.

To import a Script

The contextloader global variable is provided to a script. It will load and initialize a script resource.

contextloader.loadLibrary("res:/mylib.js");

loadLibrary() takes a String which is the ROC resource identifier of the script to load.

Example

Say you have a script library with ROC identifier res:/javascript/libs/test.js

function test()
{   return "Hello World";
}

You can import this function in your script like so...

contextloader.loadLibrary("res:/javascript/libs/test.js");

//Call imported function
test();

Library loading is recursive - an imported library may also import libraries.

All library resource identifiers must be fully qualified - relative addressing is not meaningful.

Implementation Notes

The contextloader is implemented on top of the INKFRequestContext - it will SOURCE the requested identifier as a compiled javascript Script. It then invokes the script in the loading scripts execution context.

Examples

See JSON section for example of using the well known json2.js library.