A lot of Javascript performance guides tend to emphasize two points:
- Stay within scope; looking up variables progressively through each scope is expensive.
- Don't abuse the garbage collector by creating unnecessary variables constantly.
For programs that run at 60fps or similar high speeds, is there a difference in performance? JSPerf seems to go between the two on my system, so I'd like to know a little more about how to optimize for this type of stuff. Considering the following two code samples:
var t0;
function doSomethingGlobal() {
t0 = getWhatever();
t0.func1();
t0.func2();
}
verses
function doSomethingLocal() {
var t0 = getWhatever();
t0.func1();
t0.func2();
}