I’m cleaning up a large website’s huge variables scope, normally when cleaning up these things I find the variables and var scope them.
Problem is; say I have a function declaration in a view(cfscript):
function myFunction(){
//doStuff
}
myFunction is now available in the variables scope, it is however only used on this page so i want it in the local scope.
I’ve tried:
function local.myFunction(){
//doStuff
}
//error!
var myFunction = "";
function myFunction(){
//doStuff
}
//just creates a local string and a global function...
var function myFunction(){
//doStuff
}
//no error but function is still not local...
the following however does work, it does feel kinda nasty though…
function myTMPFunction(){
//doStuff
}
var myFunction = myTMPFunction;
structDelete(VARIABLES, "myTMPFunction");
is there no better, clean way?
Based on your comment to Sergii’s post,
I would say maybe you should refactor the function into a custom tag.
I generally avoid directly outputting anything from functions and use Custom Tags instead. When I use functions I return some value (or void).
Without more specific information on what the function does, though, it will be hard to give a more concrete answer than that.
However, while not the prettiest, I think your work-around solution would also work, if you’d rather not go through the effort to use a Custom Tag.