Was this helpful?
Invoking a Function
A RushScript source file may contain JavaScript functions that compose varying applications or variations of an application. At run time, the user can pass in the name of a JavaScript function to invoke. The function will be invoked after all RushScript files have been evaluated. Note that any code not contained within a function will be executed as part of evaluating a source file. The function does not require parameters. If any are defined, they will be ignored and contain the undefined value when invoked.
The following example demonstrates using the --function command line option to specify the name of the function to invoke.
$ dr --function application1 applications.js
Following is an example of a RushScript source file with multiple functions that can be invoked at run time to vary composition.
Example RushScript file with callable functions
// Note that the following code is not in a function and will be
// executed during the initial evaluation of this script.
dr.include('common.js');

// Compose application1
function application1() {

    // Code to compose the application ...
}

// Compose application2
function application2() {

    // Code to compose the application ...
}
Functions on JavaScript objects can also be invoked. The same option (--function) is used on the command line but the syntax is slightly different: objectName.functionName. The object that is being referenced must be created by the provided JavaScript source. After the source is evaluated, the object will exist in the current context and will be obtained by the provided variable name. The following example demonstrates using the --function command line option to specify the name of an object and the function to invoke on that object.
$ dr --function myObject.application1 applications.js
Last modified date: 01/06/2023