Coldfusion Local scope outside of a function?

依然范特西╮ 提交于 2019-12-04 13:04:53

The Local scope is only defined within functions and should not be used outside of it.

Variables defined outside the functions, default to the variables scope.

//that way
myVar = 0;
//will be the same as
variables.myVar = 0;

When you refer to local.madVar2 variable, which was initialized outside the function you're essentially referring to the local.madVar2 in the variables scope i.e the variable madVar2 is stored inside a struct named local which is stored in the variables scope.

So essentially, with the proper scoping in place your code is treated as:

writeOutput("variables.local.madVar2: <BR>");     
writeDump(variables.local.madVar2);

Try dumping the variables scope just after defining the variables inside the function as:

var madVar = "madness variable";
madVar2 = "madness two variable";
writeDump(variables);
.....

You will see how the variables fall into scopes.

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