Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.