Scope of a Local variable in a cfm page?

六眼飞鱼酱① 提交于 2020-01-05 22:45:12

问题


The following is on a test.cfm page:

<cfscript>
        Local.myString = "Hello";
</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?


回答1:


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:

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.

The local scope is likewise document on that page, btw.

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



来源:https://stackoverflow.com/questions/31336408/scope-of-a-local-variable-in-a-cfm-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!