I have a section of my script that looks like:
var g = document.createElement("script");
g.src = "http://www.google-analytics.com/ga.js";
var s = document.getElementsByTagName("script");
I was curious why this code was wrapped inside a function so I started doing some reading. The way I understand it the wrapper keeps the functions and variables inside the wrapper separate from the rest of the script.
As I'm sure you were able to tell the inside the wrapper is some modified Google Analytics code which loads a secondary, external script.
Would the functions and variables in the secondary script already be kept separate from the first script? In which case I would be able to remove this wrapper as long as I don't use the "g" and "s" variables? Or would the two mix in which case the wrapper would be a good idea to maintain?