Object Functions

Object Functions:

  • Below is a list of object-manipulation functions built into HFL.
  • NOTE: These are normal functions, not object methods.
  • copyObjectProps (<source-object>, <target-object>' [, 'replace'])'
    • Copies all of the object properties of the source object to the target object. If the target object is not specified, creates a new object that is a copy of the source object.
    • If the optional 'replace' option is specified, it will modify the object properties of inner objects as well, allowing the copy operation to alter an object tree. To do this, it checks each object property value in the source object, and if its value is an object, it then checks if the target has an object property with the same key. If so, it then recursively copies the object properties of the source object's object to the target object's object.
    • The 'replace' option is a convenient way to override the defaults of format function objects, affecting not just the top-level defaults, but those of sub-fields as well.
    • EXAMPLE:
      • var fmt = getFormat('sample1.hfmt');            // Get the format object
        var formats_overrides = {
          page:    'page.simple2.hfmt',
          base:    'page_base_content2.hfl'
          };
        var overrides = {
          formats: formats_overrides
          };
        copyObjectProps(overrides, fmt, 'replace');     // Override some defaults
        fmt();                                          // Apply the format

  • deleteObjectProps (<source-object>, <target-object>)
    • Deletes the object properties listed in the source object from the corresponding properties of the target object.
    • If the source object's property value is not an object, the corresponding property of the target object will be deleted.
    • If the source object's property value is an object, and the corresponding property of the target object is also an object, then instead of deleting the property of the target object it will instead recursively apply the deletion action to the target's sub-object.
    • Thus it is easy to delete selected elements in an object tree structure, while leaving all the other object property values untouched. But this also implies that the values in the source object must not be objects if you do not want this behavior.
    • EXAMPLE:
      • var fmt = getFormat('sample1.hfmt');            // Get the format object
        var formats_deletions = {
          page:    'page.simple2.hfmt'
          };
        var deletions = {
          formats: formats_deletions
          };
        deleteObjectProps(deletions, fmt);              // Remove some defaults
        fmt();                                          // Apply the format

  • printObject (<title-string> , <object> [, <flags>])
     
    where:
    <flags>
    :=
    a hex number, consisting of one or more of:
    0x00FF
    :=
    Property depth to show
    0x0100
    :=
    show bindings
    0x0200
    :=
    show format
    0x0400
    :=
    show parent objects
    0x1000
    :=
    do not indent output
    • Prints the contents of the object to the console.
    • The <flags> option is a hex number, and can combine multiple options in one value.
    • The last two bytes specify the depth that the property list will be displayed. Thus a value of 0x001 would display the first tier of properties, a value of 0x002 would display the first tier of properties and one level of their sub-properties, and so on.
    • If the <flags> option is not specified, it defaults to showing bindings and format information, and one level of properties (0x0301).
    • If flag option 0x0200 is specified, displays any formatting instructions associated with the object, such as within a function object.
    • If flag option 0x0400 is specified, displays the contents of 'parent' prototype objects.
Previous: Filename Functions Next: Logging Functions