require([dependencies,] callback)
Method Description |
Function used to load a module only when the module is needed. When NetSuite executes the require function, it executes the callback function specified in the require function and loads the dependencies when they are required. If you add a module as a dependency and the module is never used, the dependency is never loaded.
Note:
This function conforms to the Asynchronous Module Definition (AMD) specification. For more information, see require Function. |
Returns |
void |
Global object |
|
Since |
2015.2 |
Parameters
Parameter |
Type |
Required / Optional |
Description |
Since |
---|---|---|---|---|
|
string [] |
optional |
Represents all module dependencies required by the callback function. Use the following syntax:
|
2015.2 |
|
Function |
required |
Callback function to execute. Dependent modules are not loaded until they are required. |
2015.2 |
Errors
Error Code |
Message |
Thrown If |
---|---|---|
|
Module does not exist: {module path/name} |
The NetSuite module or custom module dependency does not exist. Note that NetSuite only reports the first error encountered. If you have multiple dependent modules and you receive this error, verify that all module paths and names are correct. |
Syntax
The following example shows progressive loading of modules in a script using the require function.
define({
newInstance: function (type)
{
switch (type)
{
case 'lib1' :
require(['/lib1'], function (lib1) // Module Loader loads lib1
{
return new lib1();
})
break;
case 'lib2' :
require(['/lib2'], function (lib2) // Module Loader loads lib2
{
return new lib2();
})
break;
default :
return null;
}
}
});