Created
August 13, 2012 15:59
-
-
Save keithelliott/3342187 to your computer and use it in GitHub Desktop.
Deal with Global Functions and Properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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