Currently, if you copy a code snippet with the var keyword from inside a function to the body of the Component or Template, you get an error, stating that the var keyword can only be used inside a function.
Inside functions, the var keyword is an alias to the Local scope, so that the following expressions are the same:
function setX(){
Local.x = 1; // style-A
var x = 1; // style-B
}
But if you copy those two lines outside of the function, style-A will set x in a Struct called Local, and style-B will throw an error.
I propose that we allow the var keyword outside of a function, so that it points to the Variables scope. So that the following expressions will be the same:
component {
variables.x = 1;
var x = 1; // proposal to set x in the Variables scope
}
There are three reasons for that:
var is less typing than variables..
You can copy snippets out of functions for quick testing and/or prototyping
It is more consistent with both CFML and other languages like JavaScript