gpt4 book ai didi

inheritance - 是否可以通过扩展组件来查看特定于函数的变量?

转载 作者:行者123 更新时间:2023-12-04 06:51:26 24 4
gpt4 key购买 nike

在 Adob​​e Flex 中,可以声明一个公共(public)函数,该函数可以在扩展该函数类的类中被覆盖:

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 + "!");
}
}

看看扩展类如何访问公共(public)变量?

我想知道在 ColdFusion 中是否有可能发生这样的事情。我知道特定于组件的变量存储在“this”和“Variables”范围内,而“var”范围对于声明它的方法是私有(private)的,但是,有什么……介于两者之间吗?

p.s.抱歉,有史以来最模糊的标签....

最佳答案

我知道您要做什么,但答案是否定的,在 ColdFusion 中不可能做到这一点。这不是继承在 CF 中的工作方式。

但是,您确实有权运行该函数的父类版本;并且您可以使用组件全局范围,例如变量(或用户的 session 范围等)

<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>

关于inheritance - 是否可以通过扩展组件来查看特定于函数的变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3071711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com