cfm页面中局部变量的范围? [英] Scope of a Local variable in a cfm page?

查看:132
本文介绍了cfm页面中局部变量的范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 test.cfm 页面上的内容:

<cfscript>
        Local.myString = "Hello";
</cfscript>

myString 的范围是什么?它会在 cfm 页的其他部分还是在< cfscript> 标签所定义的位置之间可见?

What is the scope of myString? Will it be visible in other parts of the cfm page or just between the <cfscript>tags where it was defined?

推荐答案

在函数之外,该赋值设置了变量 variables.local.myString ,并且变量作用域的作用域规则也有据可查:关于作用域:变量。从文档中:

Outside of a function, that assigment sets a variable variables.local.myString, and the scoping rules of the variables scope are well documented: About scopes: variables. From the docs:


使用
cfset和cfparam标记创建的任何类型的变量的默认范围。变量作用域变量仅在创建它的页面和任何包含的页面上可用
(另请参阅
调用者作用域)。在CFC中创建的变量作用域变量
仅可用于组件及其功能,而不是实例化该组件或调用其功能的页面

The default scope for variables of any type that are created with the cfset and cfparam tags. A Variables scope variable is available only on the page on which it is created and any included pages (see also the Caller scope).Variables scope variables created in a CFC are available only to the component and its functions, and not to the page that instantiates the component or calls its functions.

本地范围

在对语言有疑问时,咨询文档始终是 start 的好地方。

Consulting the docs is always a good place to start when having questions about the language.

这篇关于cfm页面中局部变量的范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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