Skip to content

Instantly share code, notes, and snippets.

@zootella
Created July 10, 2014 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zootella/f6c3d3a790c3bdb09369 to your computer and use it in GitHub Desktop.
Save zootella/f6c3d3a790c3bdb09369 to your computer and use it in GitHub Desktop.
//make something available to the file from within a function in the file
//make sure it doesn't affect what's available in files that require this one
var color1 = "red";
var color2 = "orange";
//and we want to set two more colors, using the function below
function setColors() {
var extraColors = {color3:"yellow", color4:"green"};
for (color in extraColors) {
//module[color] = extraColors[color];//module doesn't work!
global[color] = extraColors[color];//global works, but i hope it doesn't mess up files that require this one
}
}
setColors();
//now let's see what worked
console.log("color1 is " + color1);
console.log("color2 is " + color2);
console.log("color3 is " + color3);
console.log("color4 is " + color4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment