CFLib.org – Common Function Library Project

extend()

Last updated September 12, 2013

author

Owen Knapp

Version: 1 | Requires: CF9 | Library: DataManipulationLib

Description:
This is similar to jQuery.extend(). The function will accept 0 to many structs passed to it. The first struct passed as an argument is considered the target struct. When two more more structs are passed to extend() properties from all the structs are added to the target. This is useful, for instance, if you have code that expects a struct with specific keys and defaults as a variable or argument and you want to ensure they always exist before executing any further code.

Return Values:
A struct containing all the passed-in structs appended in turn

Example:

result = extend({one="tahi"},{two="rua"},{three="toru"},{four="wha"});
writeDump(result);

Parameters:

No arguments.

Full UDF Source:

/**
 * Merge the contents of two or more structs together into the first struct.
 * v1.0 by Owen Knapp
 * v1.1 by Adam Cameron (simplified logic, making it CF9 compatible)
 * 
 * @return A struct containing all the passed-in structs appended in turn 
 * @author Owen Knapp (owen@letskillowen.com) 
 * @version 1.1, September 12, 2013 
 */
struct function extend() {
    var extended    = {};
    var arg            = "";

    for (arg in arguments){
        structAppend(extended, arguments[arg]);
    }

    return extended;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson