I know that a solution has been found but I wanted to post some code
in case anyone else was wondering how to do something similar. Note
that this will only work if you give an instance to (or can get the
instance from) the using code.
component1.cfc
=======================================
<cfcomponent output="false">
<cffunction name="init" returntype="component1" access="public"
output="false">
<cfreturn this>
</cffunction>
<cffunction name="method1" returntype="void" access="public"
output="true">
in method1
</cffunction>
</cfcomponent>
test.cfm
=======================================
<!--- create an instance and dump the structure --->
<cfset variables.comp1 = createobject('component',
'component1').init()>
<cfdump var="#variables.comp1#">
<!--- an injection method that can inject a new method into an
existing object instance --->
<cffunction name="inject" returntype="void" access="public"
output="false">
<cfargument name="method" type="any" required="true">
<cfargument name="old" type="string" required="true">
<cfset this["old" & arguments.old] = this[arguments.old]>
<cfset variables["old" & arguments.old] = variables[arguments.old]>
<cfset this[arguments.old] = arguments.method>
<cfset variables[arguments.old] = arguments.method>
</cffunction>
<!--- the new method to inject --->
<cffunction name="mymethod1" returntype="void" access="public"
output="true">
in mymethod1 <br>
<cfset this.oldmethod1()>
</cffunction>
<!--- inject the injection method and use it to inject the new method,
then cleanup --->
<cfset variables.comp1.inject = inject>
<cfset variables.comp1.inject(mymethod1, "method1")>
<cfset structdelete(variables.comp1, 'inject')>
<!--- dump the new structure --->
<cfdump var="#variables.comp1#">
<!--- test --->
<cfset variables.comp1.method1()>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CFCDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cfcdev?hl=en
-~----------~----~----~----~------~----~------~--~---