I recently read, that if a global object (i.e. document) is being called multiple times then it would increase performance of the JavaScript by encapsulating this object into a local variable.
For Example, this should technically run faster..
var doc = document;
var a = doc.getElementById("id1");
var b = doc.getElementById("id2");
var c = doc.getElementById("id3");
than this..
var a = document.getElementById("id1");
var b = document.getElementById("id2");
var c = document.getElementById("id3");
Does this performance increase remain true, even in high availability/offline capable web applications and single page applications? Will memory usage grow substantially by creating local variable counterparts of highly used global objects? Why?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…