Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Created July 28, 2015 12:03
Show Gist options
  • Save tcelestino/3ddc37c7d4d778e2d249 to your computer and use it in GitHub Desktop.
Save tcelestino/3ddc37c7d4d778e2d249 to your computer and use it in GitHub Desktop.
Detecting var globals. Create by Remy Sharp
(function (global) {
function Globals () {}
var getWindow = function () {
var iframe = document.createElement('iframe')
iframe.style.display = 'none'
document.body.appendChild(iframe)
var result = iframe.contentWindow || iframe.contentDocument
iframe.parentElement.removeChild(iframe)
return result
}
Globals.prototype.get = function() {
var iframeWindow = getWindow()
var result = []
var property;
// Window
for (property in global) {
if (!(property in iframeWindow)) {
result.push(property)
}
}
return result
};
global.globals = new Globals();
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment