Jonathon,

You're on the right track, but it's much easier than that. Here's some play
code I just whipped up:

<cfscript>
  function getVariablesExternal() {return variables;}
  function methodToInject() {return "This method was Injected";}
  myCFC = createObject("component","test").init(); // get component
  myCFC.getVariables = getVariablesExternal; // inject variable scope getter
into "this" scope
  myCFC.getVariables().injectedMethod = methodToInject; // inject a method
into CFC "variables" scope
  myCFC.getVariables().this.injectedMethod = methodToInject; // also into
public "this" scope
  writeOutput( myCFC.getVariables().privateMethod() ); // call private
method from test.cfc
  writeOutput( myCFC.injectedMethod() ); // call injected method
</cfscript>

It's really amazing the things you can do with this stuff :D

PS here's my test.cfc:

<cfcomponent>

    <cffunction name="init" access="public">
        <cfreturn this>
    </cffunction>

    <cffunction name="privateMethod" access="private">
        <cfreturn "This is a Private Method!">
    </cffunction>

    <cffunction name="publicMethod" access="public">
        <cfreturn "This is a Public Method!">
    </cffunction>

</cfcomponent>


This is actually the concept of mix-ins, there has been some more formal
code written about it, but you can do it like this, like a cfinclude file
(even with a dynamic file name) from inside the CFC, you can get a struct of
functions and loop over them, calling each or injecting them elsewhere, you
can have a mixin() method that takes a function as an argument, and so on
and so on. Really, lots of fun things here!

-- 
nathan strutz
http://www.dopefly.com/


On 10/22/07, Jonathon Stierman <[EMAIL PROTECTED]> wrote:
>
> Is it possible to programmatically add/update functions to an instantiated
> CFC?
>
> I've made one attempt to add one by calling the getMetaData function, but
> nothing I added to the meta data seemed to update the object's method
> list.
>
> Is there another way to go about doing this, or am I on the right track?
>
> Jonathon
>
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Create robust enterprise, web RIAs.
Upgrade to ColdFusion 8 and integrate with Adobe Flex
http://www.adobe.com/products/coldfusion/flex2/?sdid=RVJP

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:291777
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to