Skip to content

Instantly share code, notes, and snippets.

@keithelliott
Created August 13, 2012 15:59
Show Gist options
  • Save keithelliott/3342187 to your computer and use it in GitHub Desktop.
Save keithelliott/3342187 to your computer and use it in GitHub Desktop.
Deal with Global Functions and Properties
// Example 1: Wrapping function and passing in global variables
// self-executing function that passes in the global context via this when the file loads
(function myGlobalExample(global){
return {
testFn: function(){
var doIt = global.doItTimes(5);
return doIt;
}
};
}(this));
// Example 2: Accessing globals via the window property in browsers
function myOtherGlobalExample(){
return {
testFn: function(){
var doIt = window.doItTimes(5);
return doIt;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment