|
Hello: Can anyone tell me if there is a
difference in memory space allocation in the following two example implementations
on initializing component properties? The reason I ask, is that I'd prefer to
call the init() method from within the construction code but don't want to run
into variable memory allocation debugging down the line when the component gets
complex. Example 1: set component properties in the
pseudo-constructor space between the <cfcomponent... tag and the first
function using inline code. <cfcomponent displayname="Address
Class" hint="Address Class"> <!--- Property constructor for this
class ---> <cfscript> addressTypes =
"company,other,home,mailing,form"; variables.props = StructNew(); variables.props.addressStreet =
application.stringNull; variables.props.addressCity =
application.stringNull; variables.props.addressState =
application.stringNull; variables.props.addressPostalCode
= application.stringNull; variables.props.addressCountry =
application.stringNull; variables.props.addressType =
application.stringNull; </cfscript> Example 2: set component properties in the
pseudo-constructor space between the <cfcomponent... tag and the first
function calling a init() function. <cfcomponent displayname="Address
Class" hint="Address Class"> <!--- Property constructor for this
class ---> <cfscript> init(); </cfscript> ... The init() function… <cffunction name="init"
access="public" returntype="address"
output="false" displayname="" hint="I set values to
address instance properties."> <cfargument
name="argStreet" type="string" required="false"
default=application.stringNull/> <cfargument
name="argCity" type="string" required="false"
default=application.stringNull/> <cfargument
name="argState" type="string" required="false"
default=application.stringNull/> <cfargument
name="argPostalCode" type="string"
required="false" default=application.stringNull/> <cfargument
name="argCountry" type="string" required="false"
default=application.stringNull/> <cfargument
name="argType" type="string" required="false"
default=application.defaultAddressType/> <cfscript> addressTypes =
"company,other,home,mailing,form"; variables.props.addressStreet
= arguments.argStreet; variables.props.addressCity =
arguments.argCity; variables.props.addressState =
arguments.argState;
variables.props.addressPostalCode = arguments.argPostalCode; variables.props.addressCountry
= arguments.argCountry; variables.props.addressType =
setAddressType(arguments.argType); return this; </cfscript> </cffunction> Thanks for any thoughts, Jason D. You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm CFCDev is supported by: Katapult Media, Inc. We are cool code geeks looking for fun projects to rock! www.katapultmedia.com An archive of the CFCDev list is available at www.mail-archive.com/[email protected] |
- [CFCDEV] Component initialization and memory space allocation Jason Davey
