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