UFObject implements various support methods for objects.

Methods

  • Copy the values of properties in aValues to properties of same name in anObject.

    If a property of aValue is an object, the function will copy all the properties in that object.

    If the value of a property of aValue is a function, the function will be called with two parameters: anObject, property name. The function is responsible for assigning a value to anObject.

    Parameters

    • anObject: any

      Object to update properties

    • aValues: any

      Object to get parse and obtain values from

    Returns any

    Value of anObject

    Example: show error in TextInput

    var errorProperties: Object = {
    textField: {
    borderColor: 0xFF0000,
    backgroundColor: 0xFFCCCC
    }
    };
    // backup current properties
    var originalProperties: Object = UFObjectTools.backupProperties(SomeTextInput, errorProperties);
    // show error state
    UFObjectTools.applyProperties(SomeTextInput, errorProperties);
    // restore original settings
    UFObjectTools.applyProperties(SomeTextInput, originalProperties);
  • Create a copy of the map object, setting properties in it to values of properties in aSource.

    aMap can contain properties with basic types or properties of type Object. In that case the object properties are scanned.

    If aSource is an Array instance, a new Array instance is created else a new Object instance is used.

    Parameters

    • aSource: any

      Source object to obtain values from

    • aMap: any

      An object with various properties

    Returns any

    A copy of aMap with values obtained from a Source.

    Example

    make copy of some properties in TextInput
    <listing>
    var map = Object = {
    text: 'some text',
    textField: {
    borderColor: 0xFF0000,
    backgroundColor: 0xFFCCCC
    }
    };
    var data: Object = UFObject.backupProperties(SomeTextInput, map);
    // data.text = text of SomeTextInput
    // data.textField.borderColor = current border color of SomeTextInput
    // data.textField.backgroundColor = current background color
    </listing>
  • Combines multiple object instances.

    The method will create a new object and copies all properties (including getters and setters) from each argument to the new object.

    After processing all arguments, the method checks each argument again if it contains the initialize method specified by anInitMethod.

    If aCallInit is true, the initialize method gets called using the newly created object as its function scope.

    If aCallInit is false, a new initialize method is attached to the created object that will call all the other initialize methods with the correct function scope.

    Parameters

    • anObjects: any[]

      Object instances to combine

    • aCallInitialize: boolean = true

      When false do not call the initialize methods but create and attach a new initialize method that will call the initialize methods (if any of the other objects contains the initialize method).

    • anInitializeName: string = '__init'

      The name of the initialize method to call or null to skip.

    Returns any

    An instance being a combination of all arguments

  • Checks if an object contains a certain key. It is possible to specify multiple values.

    Parameters

    • anObject: any

      An object (keys are checked)

    • Rest ...aKeys: string[]

      One or more key names to check

    Returns boolean

    True if the object has a key that matches one of the aKeys values.

  • Copies a property/method from one object to another. If the property is a getter or setter, the method will redefine the property in the target object.

    Parameters

    • aName: string

      Name of property

    • aSource: any

      Source to copy property from

    • aTarget: any

      Target to copy property to

    Returns void

  • Copies the properties of an object. Recursively call this method for properties that are object values.

    Type Parameters

    • T extends object

    Parameters

    • anObject: T

      Object to copy

    Returns T

    copy of an object

  • See if all properties in aMatch can be found in aSource and are equal. If a property is an object, the method will call itself recursively.

    Only properties defined in aMatch are checked.

    Parameters

    • aSource: any

      Source object to test

    • aMatch: any

      Contains properties to match

    • anIgnoreCase: boolean = false

      True: ignore case of string properties, false: casing must match for properties to be equal

    Returns boolean

    True: all properties found and matching in value

  • Gets a property from an object.

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to get

    • aDefault: any

      Default value to use

    Returns any

    value from property or aDefault if it does not exist

  • Gets a property from an object and typecast it to a type.

    Type Parameters

    • T

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to get

    • aDefault: T

      Default value to use

    Returns T

    value from property or aDefault if it does not exist

  • Gets a property from an object. If there is no property, create a new value and attach it to the object.

    Type Parameters

    • T

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Name of property to get

    • aFactory: (() => T)

      Factory function to create a new value

        • (): T
        • Returns T

    Returns T

    value from property

  • Gets a property or throws an error if the property is missing.

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to get

    Returns any

    value of property

    Throws

    an error if the object does not contain the property

  • Gets a property as a certain type or throws an error if the property is missing.

    Type Parameters

    • T

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to get

    Returns T

    value of property

    Throws

    an error if the object does not contain the property

  • Checks if an object is an instance of a class. If anObject is not an object, the method will return false.

    The method will also return false if instanceOf fails with an exception.

    Parameters

    • anObject: any

      Object to check

    • aClass: any

      Class to check

    Returns boolean

    True if anObject is an instance of aClass; in all other cases false.

  • Sets a property in an object to a value. If the property can not be found, the method does nothing.

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to set

    • aValue: any

      Value to set property with

    Returns void

  • Sets a property in an object to a value. If the property can not be found, the method throws an error.

    Parameters

    • anObject: any

      Object to get property from

    • aPropertyName: string

      Property to set

    • aValue: any

      Value to set property with

    Returns void