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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson