UNPKG

apex4x

Version:

The Comprehensive ARIA Development Suite

49 lines 3.48 kB
�� Function: loop(object, functionCallback(key, value), stringType) Description: Performs a recursive loop that supports the same callback syntax for multiple object types. Returns: Referenced Object, or $A object if chained. Note: When passing an object to loop(), the stringType parameter must reflect the correct token for that object type. The function will attempt to guess if omitted, but setting an explicit declaration will always work best. The callback syntax is always as follows: function(indexOrKeyName, referencedValueOrObject), no matter which object type is being processed. Object type tokens must always be in lower case. Type Tokens "array": When object matches type Array "map": When object matches type Map "object": When object matches type Object "string": When object matches type String Example: // Loop through an array such as [1, 2, 3] $A.loop(arrayObject, function(indexNumber, object) { // Do something with object }, "array"); // Loop through an map such as new Map() $A.loop(mapObject, function(key, object) { // Do something with object }, "map"); // Loop through an object such as {key: 'value'} $A.loop(objectObject, function(key, object) { // Do something with object }, "object"); // Loop through a string such as "Whatever" $A.loop(stringObject, function(indexNumber, character) { // Do something with character }, "object"); // Or the same using chaining // Loop through an array such as [1, 2, 3] var myChain = $A([domElement1, domElement2]).loop(function(indexNumber, object) { // Do something with object }, "array"); // To return the modified element within a chain, use the "return()" method. var myElement = myChain.return();