2010-06-18 74 views
2

在Adobe Flex的,可以申报公共功能,可在扩展该函数的类的类中重写:是否可以通过扩展组件来使函数特定变量可见?

public class class1 { 
    public function method1 { 
     public var var1:string = "hello world"; 
    } 
} 

public class class2 extends class1 { 
    override public function method1 { 
     alert.show(super.var1 + "!"); 
    } 
} 

看看上面公共变种可以通过扩展类访问?

我在想,如果这样的事情在ColdFusion中是可能的。我知道特定于组件的变量存储在“this”和“Variables”作用域中,而“var”作用域对于它声明的方法是私有的,但是,它们之间存在什么...?

p.s.对不起,有史以来最模糊的标签...

+0

我设置了更有意义的标记问题。 – 2010-06-18 17:27:45

+0

谢谢。我的思想今天进展缓慢...... – 2010-06-18 18:38:05

回答

3

我明白你想要做什么,但答案是否定的,这是不可能的在ColdFusion中做到这一点。这不是继承如何在CF中工作。

但是,您有权访问运行父类的函数版本;您可以使用组件全局范围,如变量(或用户的会话范围等)

<cfcomponent displayName="parent"> 
    <cffunction name="foo"> 
     <cfset variables.foo = 1 /> 
    </cffunction> 
</cfcomponent> 

<cfcomponent displayName="child" extends="parent"> 
    <cffunction name="foo"> 
     <cfset super.foo() /> 
     <cfdump var="#variables#" /> 
    </cffunction> 
</cfcomponent> 
+0

因此,那个转储的变量与显示父类的变量范围? – 2010-06-18 18:37:26

+0

是的,没有。 super.foo()将在子对象的上下文中运行,所以当它设置variables.foo时,它将在稍后的相同请求中的该上下文(子对象的上下文)中可用。 – 2010-06-18 23:46:31

相关问题