Inheritance Coldfusion-重写使用关键字的基于标记的函数

Inheritance Coldfusion-重写使用关键字的基于标记的函数,inheritance,coldfusion,Inheritance,Coldfusion,我目前正在尝试扩展第三方CFC,它一切正常,工作正常,但是,我现在来覆盖CFC中的一个方法(我首先扩展它的全部原因)。现在,第三方CFC都是基于标签的,并且有一个名为“do”的函数,定义如下: <cffunction name="do" returntype="any" access="public" output="true" hint="I compile and execute a specific fuseaction.">

我目前正在尝试扩展第三方CFC,它一切正常,工作正常,但是,我现在来覆盖CFC中的一个方法(我首先扩展它的全部原因)。现在,第三方CFC都是基于标签的,并且有一个名为“do”的函数,定义如下:

<cffunction name="do" returntype="any" access="public" output="true" 
                hint="I compile and execute a specific fuseaction.">
        <cfargument name="action" type="string" required="true" 
                    hint="I am the full name of the requested fuseaction (circuit.fuseaction)." />
        <cfargument name="contentVariable" type="string" default="" 
                    hint="I indicate an attributes / event scope variable in which to store the output." />
        <cfargument name="returnOutput" type="boolean" default="false" 
                    hint="I indicate whether to display output (false - default) or return the output (true)." />
        <cfargument name="append" type="boolean" default="false" 
                    hint="I indicate whether to append output (false - default) to the content variable." />
        <cfargument name="passThroughReturn" type="boolean" default="false" 
                    hint="I indicate whether to allow for a return to be passed through from an action CFC." />
public any function do( Required String action, String contentVariable="", boolean returnOutput=false, boolean append=false, boolean passThroughReturn=false){
然后我得到一个关于函数名的错误,因为“do”是CF保留字

我试图通过重命名该方法并仅映射do it来解决此问题,例如:

this.do = variables.invokeDo;

public any function invokeDo( Required String action, String contentVariable="", boolean returnOutput=false, boolean append=false, boolean passThroughReturn=false){
这绕过了错误,但是如果我调用
myObject.do(..)
它只会调用超类方法


有人知道如何在CFscript中重写此方法吗?

如果您真的不能使用CFML,如果您的新cfc不需要进行类型检查,并且您不需要访问父级的私有变量,则此方法可能有效

component {

  function init(parent) {
    variables.parent = parent;
    return this;
  }

  function onMissingMethod(missingMethodName, missingMethodArguments)
  {
    if (missingMethodName == "do")
      doFunc();
    else {
      // if CF10, use invoke(), else use yucky evaluate()
    }
  }

  function doFunc()
  {
     // your new do() function
  }
}

不幸的是,我不认为有一个好的方法来实现你想要的。但是,有一些变通办法。其中一个技巧就是这样做:

component extends="OriginalComponent" {
  variables["do"] = function () {
    // new function code here
  };

  this["do"] = variables["do"];
}
它实际上并没有覆盖传统意义上的函数,但似乎可以工作:在测试时,对函数的内部和外部调用都调用新函数,而不是原始函数


我不知道这类黑客可能还有其他后果,所以要小心

奇怪的是,我今天在博客中谈到了这一点。我没有使用
do()
进行测试,但我认为这至少是同一类问题….?是的,看起来是同一个问题-看起来没有/你没有找到在CF中使用cfscript时的修复方法(不是railo)?没有“修复方法”。只是冷融合是垃圾。它是在编译器级别的,所以没有办法让它工作,您只需要不使用该语法。在CFScript中无法实现这一点,在这种情况下需要使用标记:-(是的,不应该使用保留字
do
作为函数名,但是为了保护第三方,@Henry中没有列出
do
,是的。不幸的是,使用像
do
这样的常用保留字只是自找麻烦。……必须'喜欢使用第三方代码。目前的解决方法很有效。我会看看是否找到合适的解决方法y不需要的副作用。好的,我发现了一个明显的副作用-如果在重写函数中的任何一点我想将其交给父组件函数,它就不起作用-在子函数的上下文中,“super”不被识别。