Skip to main content
Version: 8.2

Example that declares a module

Level: beginner
note

The functionality is relevant to Classic UI.

Example that uses the define() function to declare the SumModule module
/* The SumModule module implements the functionality that adds two numbers.
The module has no dependencies. Therefore, the function passes an empty array as the second argument, and the anonymous factory function does not receive parameters. */
define("SumModule", [], function () {
/* The body of the anonymous function contains the internal implementation of the module's functionality. */
var calculate = function (a, b) { return a + b; };
/* The function returns a value that is an object. In this case, the object is the module. */
return {
/* Description of the object. In this case, the module is an object that has the summ property. The summ property value is a function that has two arguments and returns the sum of those arguments. */
summ: calculate
};
});