ColdFusion中的函数访问

Moh*_*mad 1 coldfusion

有没有办法通过继承访问函数而无需设置函数访问公共?

例如:我有Foo.cfc,它扩展了Bar.cfc.如果我想从Foo.cfc调用Bar.cfc函数,我必须将函数访问权限设置为public.

如果我将函数访问权限设置为private,那么它只能从Foo.cfc访问.是否没有"中间"访问级别不是公开但不严格私有?即它只允许通过继承访问...

Lei*_*igh 6

你使用的是关键字super吗?因为私有方法应该可用于子组件,如Foo.cfc.

Foo.cfc

<cfcomponent extends="Bar">
    .....
    <cffunction name="fooMethod" access="public" ...>
         <cfreturn super.nameOfAMethodInBarCFC() />
    </cffunction>
</cfcomponent>    
Run Code Online (Sandbox Code Playgroud)


Hen*_*nry 5

如果我将函数访问权限设置为private,那么它只能从Foo.cfc访问

不对! privateColdFusion中的访问级别与protectedJava中的访问级别相同,因此您仍然可以从Foo调用Bar的私有方法