It's early so maybe I'm misunderstanding this - bu...
# fw1
j
It's early so maybe I'm misunderstanding this - but why not use the 'local' scope (or var)? "Variables that you declare with the Var keyword inside a cffunction tag or CFScript function definition are available only in the method in which they are defined, and only last from the time the method is invoked until it returns the result. The Variables scope is not the same as the function local scope, which makes variables private within a function. Always define function-local variables using the var keyword of the Local scope name."
👍 1
c
Yes. This is what I have opted for. I don’t like leaving a single copy of
<http://variables.blog|variables.blog>
open to read/writes from every possible request. To be honest, I always thought that singletons should be read only? But that is a whole new debate. Anyway, I will remove the
variables
scope [private component scope] and opt for the private function scope [var] For backward compatibility, I use:
Copy code
function foo() {
    var local = {};
}
j
You may want to read up on var foo vs local.foo. I use local.foo as I find it much easier to see at a glance that the variable is local scoped.
w
not sure just how much backwards compatibility you're after, but don't do var local = {}. it's unnecessary post cf8 i believe, and totally not required or recommended from cf10 up
c
Yes, don't do that.
var local={}
actually results in a local variable called
local
, which if explicitly scoped when used would really be
local.local
.