lr.require
Loads the specified JavaScript module.
Example | Runtime Functions |
Syntax
lr.require( "<path>" );
Argument | Comments |
---|---|
path | One of:
|
The lr.require function loads the specified JavaScript module. Enter the function manually before the beginning of the action scope.
Return Values
An object containing the members exported from the library.Parameterization
Parameterization is not applicable to this function.
Example
Contents of shapes.js:
var circle = lr.require('circle.js') var square = lr.require('square.js') exports.circle = circle; exports.square = square;
Contents of circle.js:
var PI = Math.PI; exports.area = function (r) { return PI * r * r; }; exports.circumference = function (r) { return 2 * PI * r; };
Contents of square.js:
exports.area = function (w) { return w * w; }; exports.circumference = function (w) { return 4 * w; };
Contents of Lib2/package.json:
{ "name" : "shapes", "main" : "shapes.js" }
Usage in script:
var lib1 = lr.require('Lib1/shapes.js'); var lib2 = lr.require('Lib2'); function Action() { // Calculate the area of a square of width 5 lr.outputMessage(lib1.square.area(5)); // Calculate the area of a circle of radius 5 lr.outputMessage(lib1.circle.area(5)); // Calculate the area of a square of width 5 lr.outputMessage(lib2.square.area(5)); // Calculate the area of a circle of radius 5 lr.outputMessage(lib2.circle.area(5)); return 0; }