Mendix Client 4 API Documentation


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(chain, callback, scope)

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
chain Array The Array of Functions to execute.
callback Function (Optional) callback to execute at the end of the chain.
scope Object The object in which scope to execute the functions in.

Examples

mendix.lang.sequence(this, [
    function(callback) {
        callback(); // sync
    },
    function(callback) {
        setTimeout(callback, 100); // async
    }
], function() {
    console.log("Completed");
});

collect(chain, callback, scope)

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
chain Array The Array of Functions to execute.
callback Function (Optional) Callback to execute at the end of the chain.
scope Object The object in which scope to execute the functions in.

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.

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]

inArray(arr, elem)

This method returns true if element elem exists in Array arr.

Parameters

Name Type Description
arr Array The Object to clone.
elem Any The value to check for.

Returns

Type Description
Boolean true if elem exists in arr, false otherwise

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'