Namespace: objects

core. objects

The core.objects package is a modular JavaScript library that provides extra Object methods and implementations.

Author:
License:

Methods


forEach(object, callback [, context] [, breaker])

Executes a function on each item in the object. Each invocation of iterator is called with three arguments: (value, key, ref).

Parameters:
Name Type Argument Default Description
object Object

The reference of the object to enumerate.

callback function

The function to run on each item in the object. This function can contain a simple command (for example, a trace() statement) or a more complex operation, and is invoked with three arguments; the value of an item, the key of an item, and the object reference : function callback(item:, key:, ref:Object):void;.

context Object <optional>
null

An object to use as this for the callback function.

breaker * <optional>
null

value to stop the enumeration. If this argument is null the behaviour is forgotten.

Example
var object = { one:1 , two:2 , three:3 , four:4 , five:5 } ;

var action = function( value , key , ref )
{
    trace( "key:" + key + " value:" + value ) ;
    return value ;
}

forEach( object , action ) ;

trace( "----" ) ;

forEach( object , action, null, 3 ) ;

trace( "----" ) ;

forEach( [1,2,3,4] , action ) ; // use the Array.forEach method over Array objects.

fuse(src, srcPos, dest, destPos, length)

Copies an array or vector from the specified source (array or vector), beginning at the specified position, to the specified position of the destination object. A subsequence of array components are copied from the source referenced by src to the destination referenced by dest. The number of components copied is equal to the length argument. The components at positions srcPos through srcPos+length-1 in the source array are copied into positions destPos through destPos+length-1, respectively, of the destination object. If the src and dest arguments refer to the same array object, then the copying is performed as if the components at positions srcPos through srcPos+length-1 were first copied to a temporary object with length components and then the contents of the temporary array were copied into positions destPos through destPos+length-1 of the destination array.

If src is null, then a ArgumentError is thrown and the destination array is not modified.

If dest is null, then dest is the src reference.

Parameters:
Name Type Description
src Array | Object

The source array or vector to copy.

srcPos number

The starting position in the source array.

dest Array | Object

The destination array or vector.

destPos number

The starting position in the destination data.

length number

The number of array elements to be copied.

Returns:

The copy reference.

Example
var ar1 = [1,2,3,4] ;
var ar2 = [5,6,7,8] ;
fuse( ar1 , 2 , ar2 , 2 , 2 ) ;
trace( dump( ar2 ) ) ; // [5,6,3,4]

members(o [, byValue])

Returns all the public members of an object, either by key or by value.

Parameters:
Name Type Argument Default Description
o object

The target object to enumerate.

byValue boolean <optional>
false

The optional flag indicates if the function return an Array of strings (keys) or of values.

Returns:

An array containing all the string key names or values (if the #byValue argument is true). The method returns null if no members are finding.

Example
var o = { a : 5 , b : 6 } ;
trace( core.dump( core.objects.members( o ) ) ) ; // [a,b]
trace( core.dump( core.objects.members( o , true ) ) ) ; // [5,6]

merge(target, source [, overwrite])

Merging enumerable properties from a specific Object to a target Object.

Parameters:
Name Type Argument Default Description
target Object

The target object to merge.

source Object

The source object reference.

overwrite boolean <optional>
true

The optional flag to indicates if the merge function can override the already existing properties in the target reference (default true).

Returns:

The merged target reference.

Example
var target = { a : 5 , b : 6 } ;
var from   = { a : 1 , b : 2 , c: 3 } ;
trace( dump( merge( target , from ) ) ) ; // {a:1,b:2,c:3}