To which extent does it make sense to pass plenty of global values to an IIFE?
The common thing is just to pass 3 as far as I see everywhere (window, document and undefined). But... would it make sense to pass more if they are used more than 10 times in the code just for the fact of minification?
In my case I found the global variable Math
14 times in the code. It would make sense to pass it to an IIFE in order to save 42 bytes. Which in this case is not a lot, but if we sum bit by bit different global variables, then it would always make sense to pass as many global variables as possible, right? (Symbol, Object, Error, Date, JSON...)
(function($, window, document, Math, undefined) {
$.fn.mydemo = function() {
};
}(jQuery, window, document, Math));
Then, why isn't this a common approach?
Update:
To explain the 42 bytes of reduction:
- Math = 4 characteres
- 1 character = 1 byte
- 14 times Math = 56 bytes
- Math will get replaced by a single character after minification
- As the function can be defined as function($, w, d, m, u)
- 14 characters of the shorten word Math (m) = 14 bytes
- 56 - 14 = 42 bytes of reduction