mendix.lang
The mendix.lang
object contains a library of language helpers.
Methods
map(array, func)
The map function invokes func on each element in array and returns an Array with all results.
Parameters
Type | Description |
---|---|
Array | The array of items to be mapped. |
Function | The function to invoke on all items. |
Returns
Type | Description |
---|---|
Array | The list of results. |
Examples
mendix.lang.map([1,2,3], function(x) { return x * 2; }); // [2,4,6]
sequence(scope, chain, callback)
This method takes an array of Functions in chain and executes them serially. 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 | Description |
---|---|---|
scope | Scope | The scope to execute functions in. |
chain | Array | The Array of Functions to execute. |
callback | Function | (Optional) Callback to execute at the end of the chain. |
Returns
-
Examples
mendix.lang.sequence(this, [
function(callback) {
callback(); // sync
},
function(callback) {
setTimeout(callback, 100); // async
}
], function() { console.log("Completed"); });
collect(scope, chain, callback)
This method takes an array of Functions in chain and executes them in parallel. It is used where several asynchronous calls are not interdependant 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 | Description |
---|---|---|
scope | Scope | The scope to execute functions in. |
chain | Array | The Array of Functions to execute. |
callback | Function | (Optional) Callback to execute at the end of the chain. |
Returns
-
Examples
mendix.lang.collect(this, [
function(callback) {
setTimeout(callback, 100); // async
},
function(callback) {
setTimeout(callback, 100); // async
},
function(callback) {
setTimeout(callback, 100); // async
}
], function() { console.log("Completed"); });
delay(func, condition, period)
This method delays the execution of a Function func until Function condition returns true. The parameter period is optional and specifies the re-try interval.
Parameters
Name | Type | Description |
---|---|---|
func | Function | The Function to delay. |
condition | Function | The Function to check the condition(s). |
period | Number | (Optional) Retry interval in milliseconds. Defaults to 500. |
Returns
-
arraySubtract(source, _target _)
This method removes elements in Array target from Array source if these elements exist in Array source.
Parameters
Name | Type | Description |
---|---|---|
source | Function | The Array to remove elements from. |
target | Function | The Array with elements to be removed. |
Returns
Type | Description |
---|---|
Array | The filtered source Array. |
Examples
mendix.lang.arraySubtract([1,2,3], [1,2]); // [3]
dupObject(obj)
This method performs a deep-clone of the Object obj.
Parameters
Name | Type | Description |
---|---|---|
obj | Object | The Object to clone. |
Returns
Type | Description |
---|---|
Object | The cloned object. |
inArray(arr, el)
This method returns true if element el exists in Array arr.
Parameters
Name | Type | Description |
---|---|---|
arr | Array | The Object to clone. |
val | Any | The value to check for. |
Returns
Type | Description |
---|---|
Boolean |
Examples
mendix.lang.inArray([1,2,3], 1); // true
getUniqueId()
This method returns a String value that is unique for the current session.
Returns
Type | Description |
---|---|
String | A session-unique String |
Examples
mendix.lang.getUniqueId(); // '1318867312340-124'
Parameters
-