Javascript Object

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Methods)
(Methods)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
  
 
== General ==
 
== General ==
 +
 +
This object expose javascript Object operations.
  
 
== Methods ==
 
== Methods ==
Line 19: Line 21:
 
'''dest''' Destination object. Does nothing if not an object.<br/>
 
'''dest''' Destination object. Does nothing if not an object.<br/>
 
'''src''' Source object. Does nothing if not an object.<br/>
 
'''src''' Source object. Does nothing if not an object.<br/>
'''flags''' Flags controlling the operation. See Object properties for description.<br/>
+
'''flags''' Numeric. Flags controlling the operation. See Object properties for description.<br/>
'''props'''  
+
'''props''' Optional list of properties to copy. Comma separated list or Array. No property will be copied if this parameter is given and empty.<br/>
 +
'''prefix''' Optional, string. Copy only proprties starting with given prefix. This applies for names given in ''props'' also.<br/>
 +
'''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.<br/>
 +
Return:<br/>
 +
The number of assigned properties.
 +
 
 +
Flags:<br/>
 +
'''Object.AssignSkipPrefix''' Skip given prefix in property name when setting in destination. This applies for names given in ''props'' also.<br/>
 +
'''Object.AssignSkipNull''' Skip source properties with ''null'' value.<br/>
 +
'''Object.AssignSkipUndefined''' Skip source properties with ''undefined'' value.<br/>
 +
'''Object.AssignSkipEmpty''' Skip source properties with non object value evaluated to empty string.<br/>
 +
'''Object.AssignSkipObject'''  Skip source properties with object value.<br/>
 +
'''Object.AssignSkipArrayProps''' Skip source non index properties it its an Array.<br/>
 +
'''Object.AssignSkipArrayIndex''' Skip source index properties it its an Array.<br/>
 +
'''Object.AssignDeepCopy''' Deep copy objects. Set reference only if this flag is not set.<br/>
 +
'''Object.AssignFreezeCopy''' Freeze destination and all copied objects if deep copy is requested.<br/>
 +
'''Object.AssignSkipExist''' Skip (do not assign) existing properties in destination. This is handled after final property name is resolved (prefix removed/added).<br/>
 +
 
 +
A runtime error (function call failed) will be raised if:<br>
 +
* 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:<br/>
 +
The following objects implement deep copy allowing them to keep the internal data: Array, RegExp, MatchingItem.<br/>
 +
Any other object will loose any specific internal data. Only object properties will be copied.<br/>
  
  
Line 35: Line 69:
 
Return:<br/>
 
Return:<br/>
 
Object containing all global data of the calling script.
 
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 ifor assignProps() function.

Latest revision as of 10:40, 9 September 2024

[edit] General

This object expose javascript Object operations.

[edit] 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 of the calling script.
Parameters:
obj Object to list keys for. List calling script's global data object keys if this parameter is not given.
Return:
Array of key values. null if given object has no properties (e.g. obj=undefined)


  • global()

Retrieve the context (data) of the calling script.
Return:
Object containing all global data of the calling script.

[edit] Properties

  • AssignSkipPrefix,AssignSkipNull,AssignSkipUndefined,AssignSkipEmpty,AssignSkipObject,AssignSkipArrayProps,AssignSkipArrayIndex,AssignDeepCopy,AssignFreezeCopy,AssignSkipExist,AssignFilled,AssignFilledSkipObject

Numeric flags used ifor assignProps() function.

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers