Javascript Object
General
This object expose javascript Object operations.
Methods
- assign(dest[,src[,src1 ...])
Assign object(s) properties to another object.
Parameters:
dest Destination object. Does nothing if not an object.
src Source object. Does nothing if not an object.
src1 ... Other source object(s). Does nothing if not an object.
Return:
Given dest data.
- assignProps(dest,src[,flags,props,prefix,addPrefix])
Assign object properties to another object.
Parameters:
dest Destination object. Does nothing if not an object.
src Source object. Does nothing if not an object.
flags Numeric. Flags controlling the operation. See Object properties for description.
props Optional list of properties to copy. Comma separated list or Array. No property will be copied if this parameter is given and empty.
prefix Optional, string. Copy only proprties starting with given prefix. This applies for names given in props also.
addPrefix Optional, string. Prefix to be added to property name when assigned. Prefix is added after removing the one given in prefix if flags indicate it should be removed.
Return:
The number of assigned properties.
Flags:
Object.AssignSkipPrefix Skip given prefix in property name when setting in destination. This applies for names given in props also.
Object.AssignSkipNull Skip source properties with null value.
Object.AssignSkipUndefined Skip source properties with undefined value.
Object.AssignSkipEmpty Skip source properties with non object value evaluated to empty string.
Object.AssignSkipObject Skip source properties with object value.
Object.AssignSkipArrayProps Skip source non index properties it its an Array.
Object.AssignSkipArrayIndex Skip source index properties it its an Array.
Object.AssignDeepCopy Deep copy objects. Set reference only if this flag is not set.
Object.AssignFreezeCopy Freeze destination and all copied objects if deep copy is requested.
Object.AssignSkipExist Skip (do not assign) existing properties in destination. This is handled after final property name is resolved (prefix removed/added).
A runtime error (function call failed) will be raised if:
- destination object is frozen
- deep copy is required and source contains recursive references
Recursive reference example:
var a = {a1:1}; var b = {b1:1,a:a}; a.b = b; src = {a:a, b:b} var dest = {}; Object.assignProps(dest,src,Object.AssignDeepCopy);
Deep copy objects:
The following objects implement deep copy allowing them to keep the internal data: Array, RegExp, MatchingItem.
Any other object will loose any specific internal data. Only object properties will be copied.
- keys(obj)
Retrieve the list of keys of a given object.
Parameters:
obj Object to list keys for
Return:
Array of property names (strings)
- values(obj)
Retrieve the list of property values of a given object.
Parameters:
obj Object to list values for
Return:
Array of object property values
- entries(obj)
Retrieve the list of entries of a given object.
Parameters:
obj Object to list entries for
Return:
Array of Array(s). Each item is an Array with 2 items: index 0 is property name, index 1 is property value
- keysCustom(obj[,flags[,filterName[,filterValue[,appendTo]]]])
- valuesCustom(obj[,flags[,filterName[,filterValue[,appendTo]]]])
- entriesCustom(obj[,flags[,filterName[,filterValue[,appendTo]]]])
Custom variant for keys(), values() and entries() functions.
Parameters:
obj Object to handle.
flags Optional numeric flags controlling the operation.
filterName Optional filter (white list, process only if matches) for property name. RegExp or MatchingItem.
filterValue Optional filter (white list, process only if matches) for property value. RegExp or MatchingItem.
appendTo Optional Array to append to.
Return:
Array or null.
Flags:
Object.ArrayPropsForceBasicVal Force basic, non object, type for values (ignored in keysCustom()).
Object.ArrayPropsAutoNum Automatically convert key/value to number/boolean if possible. Values/entries: ignored if Object.ArrayPropsForceBasicVal is not set
Object.ArrayPropsEmptyNull Return null if result is empty. Ignored if appendTo is given.
Object.ArrayPropsSkipNull Do not process properties with null value.
Object.ArrayPropsSkipUndefined Do not process properties with undefined value.
Object.ArrayPropsSkipObject Do not process properties with object value.
Object.ArrayPropsSkipEmpty Do not process properties evaluating to empty strings.
Object.ArrayPropsNameValObj Build object array entries (object with name/value properties). Applicable when building entries.
- global()
Retrieve the context (data) of the calling script.
Return:
Object containing all global data of the calling script.
Properties
- AssignSkipPrefix,AssignSkipNull,AssignSkipUndefined,AssignSkipEmpty,AssignSkipObject,AssignSkipArrayProps,AssignSkipArrayIndex,AssignDeepCopy,AssignFreezeCopy,AssignSkipExist,AssignFilled,AssignFilledSkipObject
Numeric flags used by assignProps() function.
- ArrayPropsForceBasicVal,ArrayPropsAutoNum,ArrayPropsEmptyNull,ArrayPropsSkipNull,ArrayPropsSkipUndefined,ArrayPropsSkipObject,ArrayPropsSkipEmpty,ArrayPropsNameValObj
Numeric flags used by keysCustom(), valuesCustom() and entriesCustom() functions.