Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created February 5, 2015 10:12
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 lsauer/110cb28786cc830d2495 to your computer and use it in GitHub Desktop.
Save lsauer/110cb28786cc830d2495 to your computer and use it in GitHub Desktop.
find and set the globalObject in JavaScript
"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