Hi everyone! Lately i had a discussion with one of my coworkers about this issue:
I have object named MyObject with method named launch. On every launch method call, method searches for TweenMax at global scope. Normally i would do:
MyObject.launch = function(){
var domName = "#dom-" + String(Math.round(Math.random()*100));
TweenMax.to(domName,1,{x:200});
}
Problem begins, when this method fires on every user scroll, which can be A LOT (especially in Firefox). My question is this: Isnt better to create an instance of TweenMax as a property of MyObject like this to reach better performance?
MyObject.TweenMax = TweenMax;
MyObject.Math = Math;
MyObject.launch = function(){ // Fires VERY often
var Math = this.Math,
TweenMax = this.TweenMax,
domName = "#dom-" + String(Math.round(Math.random()*100));
MyObject.TweenMax.to(domName,1,{x:200});
}
In this scenario i would completely avoid of any global scope reaches. Please keep in mind performance-friendliness. However i still have a bad feeling, that this is not a good approach, but I dont know why. Any of your comments are deeply appreciated.