【发布时间】:2015-07-09 04:19:44
【问题描述】:
在 CF10 中,我想使用 TestHelper 对象中的 onMissingMethod 函数访问变量 Test 对象,但出现错误。
Test.cfc
component {
public Any function init(){
instance = { x = 1 };
return this;
}
public numeric function getX(){
return instance.x;
}
}
TestHelper.cfc
component {
public Any function init( ){
variables.testObj = new Test();
return this;
}
public any function onMissingMethod( required string missingMethodName, required struct missingMethodArguments ){
var func = variables.testObj[ arguments.missingMethodName ];
return func( argumentCollection = arguments.missingMethodArguments );
}
}
调用对象
obj = new TestHelper();
writeOutput( obj.getX() ); //Element INSTANCE.X is undefined in VARIABLES
在 CF10 中,这给了我一个错误,即元素 X 在实例中未定义。它似乎无法识别变量实例。我可以在 TestHelper 中显式定义 getX 函数,但我希望我可以使用 onMissingMethod 函数。
我是否误解了 onMissingMethod 应该如何在这里工作? FWIW,代码在 Railo 中工作。
【问题讨论】:
标签: coldfusion coldfusion-10 railo