Access keys

ObjectUtil

Kind of class: class
Inherits from: BasicClass
Author: Simon Wacker, Martin Heidegger
Classpath: org.as2lib.util.ObjectUtil
File last modified: Wednesday, 21 September 2005, 18:42:40
ObjectUtil contains fundamental methods to efficiently and easily work
with any type of object.

Class properties

TYPE_BOOLEAN

static TYPE_BOOLEAN:String = "boolean"
(read,write)
Constant for objects of type boolean.
See also:

TYPE_FUNCTION

static TYPE_FUNCTION:String = "function"
(read,write)
Constant for objects of type function.
See also:

TYPE_MOVIECLIP

static TYPE_MOVIECLIP:String = "movieclip"
(read,write)
Constant for objects of type movieclip.
See also:

TYPE_NULL

static TYPE_NULL:String = "null"
(read,write)
Constant for the value null.
See also:

TYPE_NUMBER

static TYPE_NUMBER:String = "number"
(read,write)
Constant for objects for type number.
See also:

TYPE_OBJECT

static TYPE_OBJECT:String = "object"
(read,write)
Constant for objects of type object.
See also:

TYPE_STRING

static TYPE_STRING:String = "string"
(read,write)
Constant for objects of type string.
See also:

TYPE_UNDEFINED

static TYPE_UNDEFINED:String = "undefined"
(read,write)
Constant for the value undefined.
See also:

Class methods

compare

static function compare (
obj1, obj2) : Boolean
Checks if two passed-in parameters are equal.

It uses different strategies by the first passed-in obj1.

  • If obj1 is a primitive it compares it with == operator.
  • If obj1 implements Comparable it calls compare()
    to compare both passed-in parameters
  • Any different case compares the structure of both objects.

It compares complex objects (that do not implement Comparable)
only if they are instances of the same class. A different class (even
if its only a extended class) will be handled as not equal.

It compares complex objects recursivly. It handles back references in
a proper way.

Parameters:
obj1:
object to be compared
obj2:
object to compare with passed-in obj1
Returns:
true if both parameters are equal

compareTypeOf

static function compareTypeOf (
firstObject, secondObject) : Boolean
Compares the results of an execution of the typeof method applied to
both passed-in objects.
Parameters:
firstObject :
the first object of the comparison
secondObject:
the second object of the comparison
Returns:
true if the execution of the typeof method returns the
same else false

isExplicitInstanceOf

static function isExplicitInstanceOf (
object, clazz:Function) : Boolean
Checks if the passed-in object is an explicit instance of the passed-in
clazz.

That means that true will only be returned if the object was instantiated
directly from the given clazz.

Parameters:
object:
the object to check whether it is an explicit instance of clazz
clazz :
the class to use as the basis for the check
Returns:
true if the object is an explicit instance of clazz else
false

isInstanceOf

static function isInstanceOf (
object, type:Function) : Boolean
Checks if the passed-in object is an instance of the passed-in
type.

If the passed-in type is Object, true will always be
returned, because every object is an instance of Object, even null
and undefined.

Parameters:
object:
the object to check
type :
the type to check whether the object is an instance of
Returns:
true if the passed-in object is an instance of the given
type else false

isPrimitiveType

static function isPrimitiveType (
object) : Boolean
Checks if the passed-in object is a primitive type.

Primitive types are strings, numbers and booleans that are not created via the
new operator. For example "myString", 3 and true are
primitive types, but new String("myString"), new Number(3) and
new Boolean(true) are not.

Parameters:
object:
the object to check whether it is a prmitive type
Returns:
true if object is a primitive type else false

isTypeOf

static function isTypeOf (
object, type:String) : Boolean
Checks if the result of an execution of the typeof method on the
passed-in object matches the passed-in type.

All possible types are available as constants.

Parameters:
object:
the object whose type to check
type :
the string representation of the type
Returns:
true if the object is of the given type

stringify

static function stringify (
object) : String
Stringifies the passed-in object using the stringifier returned by the
static org.as2lib.Config.getObjectStringifier method.
Parameters:
object:
the object to stringify
Returns:
the string representation of the passed-in object

typesMatch

static function typesMatch (
object, type:Function) : Boolean
Checks if the type of the passed-in object matches the passed-in
type.

Every value (even null and undefined) matches type
Object.

Instances as well as their primitive correspondent match the types
String, Number or Boolean.

Parameters:
object:
the object whose type to compare with the passed-in type
type :
the type to use for the comparison
Returns:
true if the type of the object matches the passed-in
type else false