There are several functions to perform operations on objects.
The best place to look at the JavaScriptUtil API documentation, that have a complete list of functions. Here, the idea is not to replicate that information, but to give a basic understanding.
The getObject function returns a reference to a given named object. It searches for elements by name or identifier. When more than one is found, the result is an array. When none, null.
Examples:<div id="myDiv"></div>
<input name="text">
<input type="checkbox" name="check" value="0">
<input type="checkbox" name="check" value="1">
<input type="checkbox" name="check" value="2">
getObject("myDiv") -> The div element reference
getObject("text") -> The text field reference
getObject("checkbox") -> The array containing the checkbox references
The isEmpty and isUndefined functions test if a given object is valid. Empty means an empty string (""), null or NaN (not a number), while undefined means an object does not exist.
Examples:isEmpty("") -> true
isEmpty(null) -> true
isEmpty(1 / 0) -> true (NaN)
isEmpty("abc") -> false
isEmpty(1) -> false
isUndefined(anUndefinedVariable) -> trueThe decode, select, ifEmpty and ifNull functions receive several parameters and return one of them, according to certain conditions.
Examples:var index = 3; var emptyString = ""; decode(index, 1, "One", 2, "Two", 3, "Three", "Unknown") -> "Three" decode(index, "a", "A", "b", "B", "?") -> "?" (the default) select(index == 10, "Ten", index > 10, "More", "Less") -> "Less" (the default) ifEmpty(emptyString, "EMPTY") -> "EMPTY" ifEmpty(index, "EMPTY") -> 3 ifNull(emptyString, "NULL") -> "" ifNull(null, "NULL") -> null
The booleanValue function test if an object could be interpreted as a boolean true or false.
Examples:booleanValue("true") -> true
booleanValue("") -> false
booleanValue("1") -> true
booleanValue("F") -> false
The debug function convert an object into a string, showing each property. Perhaps the best name for this function would be describe.
Examples:var person = {name:"John", age:35};
debug(person) -> "[object Object]
--------------------
age = 35
name = John"
The functionName and invoke functions allows working with function references.
Examples:functionName(Number) -> "Number"
var map = new Map();
functionName(map) -> "Map"
invoke("trim", " hello ") -> "hello"
invoke("left", ["abcde", 2]) -> "ab"
| Previous: Working with strings |
Table of Contents | Next: Working with arrays |