Created
February 5, 2015 10:12
-
-
Save lsauer/110cb28786cc830d2495 to your computer and use it in GitHub Desktop.
find and set the globalObject in JavaScript
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
"use strict"; | |
if(!this.hasOwnProperty('globalScope')){ | |
var globalScope; | |
try { | |
globalScope = Function('return this')(); | |
}catch(ex){ | |
//extend else-if cases for other globalObject-names as needed... | |
if(this && this.hasOwnProperty && this.hasOwnProperty('window')){ | |
globalScope = window; | |
}else{ | |
throw 'globalScope not found'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment