建议在本地缓存全局变量以获得更好的性能,如下所示:
function showWindowSize() {
var w = window;
var width = w.innerWidth;
var height = w.innerHeight;
alert("width: " + width + " height: " + height);
}
使用“this”关键字时也是如此,还是已经缓存?
例子:
Game.prototype.runGameLoop = function() {
var self = this;
self.update();
self.draw();
};