在ColdFusion中,如何明确引用“THIS” Application.cfc中定义的范围? [英] In ColdFusion, how do you explicitly reference the "THIS" scope defined in Application.cfc?

查看:199
本文介绍了在ColdFusion中,如何明确引用“THIS” Application.cfc中定义的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来显式引用Application.cfc中定义的THIS范围?

Is there a way to explicitly reference the THIS scope defined in Application.cfc?

说我有一个像这样的Application.cfc:

Say I have an Application.cfc like this:

component {
this.name="MyApplication"
..

从网站上的任何网页,您可以以这种方式访问​​this.name ...

I know that from any page in the site, you can access this.name this way...

<cfoutput>#this.name#</cfoutput> 

...但是如果你在另一个组件中,你将如何到达Application.cfc的this 范围?是否可以不移除var?

...but if you are in another component, how would you reach the Application.cfc's "this" scope? Is it possible without handing the var off?

Adob​​e文档说,您可以通过使用实例或对象名称作为前缀来引用THIS作用域。我尝试了Application.this.name,但它不工作。

Adobe documentation says that you can reference the "THIS" scope by using the instance or object name as a prefix. I tried Application.this.name but it didn't work.

推荐答案

在Application.cfc中的执行之外是不可访问的。 ColdFusion在运行时将this.name复制到application.name中,因此您可以从应用程序中的任何位置访问application.name。对于this中的其他设置,它们似乎可以从您的页面访问,因为页面通过OnRequest()方法包含在application.cfc执行周期中。

Most of the things that are set in "this" in Application.cfc are not accessible outside the execution of it. ColdFusion copies this.name into application.name at runtime, so you can access application.name from anywhere in your application. For the other settings in "this", they appear to be accessible from your pages because the pages are included into the application.cfc execution cycle by the OnRequest() method.

一旦你实例化一个CFC并且在它的方法里面工作,this的上下文就会改变CFC的构造函数。

Once you instantiate a CFC and work inside it's methods, the context of "this" changes to the constructor of that CFC.

这篇关于在ColdFusion中,如何明确引用“THIS” Application.cfc中定义的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆