I am creating a game and one of the things I am doing to prevent users from inputting code is putting the entire page into a self invoking function. If all of the variables are local, then they will not be accessible outside of the function.
But instead of putting all of the scripts into the same file and putting a function around it, is there a way I could put a function around the javascript that creates the other scripts, or somehow insert the other scripts inside the same function. If not, is there a way I could do this?
Example:
file.js looks like this:
var a = 1;
index.html looks like this:
!function() {
//loads the js file
var script = document.createElement("script");
script.setAttribute("src", "file.js");
//could i do this?
script.appendChild(script);
//will a be undefined?
alert(a);
}();