Breaking change: Remove unqualified definitions & new operator
-
I've been working on the scripting engine for the last days (implementing proper callstacks and local variable dumps when using breakpoints). As a side effect of these efforts, I've removed the possibility to define global variables without the
var
keyword. So this code:var someFunkyVariable = 5; /// hundreds of lines later someFunkYVariable = 10; // hundreds of lines later if(someFunkyVariable == 5) { CrashAndDeleteRootUser(); }
will throw a script error at the second definition:
Line 5, column 3: Unqualified assignments are not supported anymore. Use `var` or `const var` or `reg` for definition
. This will help to avoid nasty bugs which are extremely annoying to track down (plus enforce a better coding style). This however is not standard Javascript behaviour (but there is a dialect of Javascript called "strict" Javascript which does the same thing.
One caveat is that the standardfor
loop syntaxalso throws an error message, becausei = 0
is a unqualified definition. The solution is to just definei
once (or as local variable to be 100% thread-safe):var i = 0; for(i = 0; i < 200; i++) doSomething(); for(i = 375; i < 500; i++) doSomethingElse(); inline function runsOnThreadOne() { // Using local variables makes sure that the iterator value is not // changed by the other thread local i = 0; for(i = 0; i < 200; i++) doSomething(); }; inline function runsOnThreadTwo() { local i = 0; for(i = 0; i < 200; i++) doSomethingElse() };
I also removed the
new
operator because it seducts people to use the weirder parts of the Javascript language. -
OK, I admit the for loop thing was one bit too much, so I reverted this :)
You can still use the standard
for(i = 0...
syntax...