I know that it’s a good idea to cache objects that will be used many times. But what about if I will use the following many times:
var chacheWindow = window;
var chacheDocument = document;
var chacheNavigator = navigator;
var chacheScreen = screen;
var chacheWindowLocationHash = window.location.hash;
var chacheDocumentBody = document.body;
Maybe it is only good to chace stuff between <html></html>? Please explain.
The point of caching is to avoid either:
Typing long names repeatedly
Every one of your examples has a longer name then the original so you don’t get that benefit
Avoiding making an expensive operation repeatedly (or a slightly costly operation, e.g.
array.lengthbefore aforloop, a very large number of times)There is no sign that you are getting that benefit either.
You probably shouldn’t be copying the references to local variables at all.