A collection of language helpers.
Methods
(static) collect(chain, callbacknullable, scopenullable)
Executes a chain of functions
in parallel. It is used where several
asynchronous calls are not interdependent but do share a blocking
condition.
The functions
in chain
should each accept an empty callback function
as their first and only parameter and invoke this callback on completion.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
chain |
Array.<module:mendix/lang~ChainCallback> | array of functions to execute in parallel |
|
callback |
function |
<nullable> |
function to execute at the end of the chain |
scope |
Object |
<nullable> |
object in which scope to execute the functions in |
Example
lang.collect([
function(callback) {
setTimeout(callback, 100); // async
},
function(callback) {
setTimeout(callback, 100); // async
},
function(callback) {
setTimeout(callback, 100); // async
}
], function() {
console.log("Completed");
}, this);
(static) delay(func, condition, periodnullable) → {number}
Delays the execution of function func
until the condition return true.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
func |
function | delayed function |
|
condition |
function | function predicate which delays |
|
period |
number |
<nullable> |
retry interval in milliseconds, defaults to 500 |
- Deprecated:
- since version 7.23, just use setTimeout instead
Returns:
timeout identifier
- Type
- number
(static) getUniqueId() → {string}
Returns a unique identifier
Returns:
unique identifier
- Type
- string
(static) map(objOrArray, func, scopenullable) → {Array}
Invokes func
on each element in objOrArray
and returns an array with
the mapped elements.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
objOrArray |
Object | Array | elements to be mapped |
|
func |
function | function to invoke on all elements |
|
scope |
Object |
<nullable> |
object in which scope to execute the functions in |
- Deprecated:
- since version 7.23, just use Array.prototype.map instead
Returns:
array with the results
- Type
- Array
Example
lang.map([1, 2, 3], function(x) {
return x * 2;
}); // [2, 4, 6]
(static) nullExec(callback)
Calls the callback if it exists.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | function to call |
- Deprecated:
- since version 7.0, just use if (callback) callback(); expression instead
(static) sequence(chain, callbacknullable, scopenullable)
Executes a chain of functions
in sequence. It is used to sequence the
execution of both synchronous and asynchronous calls.
The functions
in chain
should each accept an empty callback function
as their first and only parameter and invoke this callback on completion.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
chain |
Array.<module:mendix/lang~ChainCallback> | array of functions to execute in sequence |
|
callback |
function |
<nullable> |
function to execute at the end of the chain |
scope |
Object |
<nullable> |
object in which scope to execute the functions in |
Example
lang.sequence([
function(callback) {
callback(); // sync
},
function(callback) {
setTimeout(callback, 100); // async
}
], function() {
console.log("Completed");
}, this);
Type Definitions
ChainCallback(callback)
Callback for functions to be called in a chain.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | invoke this function on completion |