Skip to content

Instantly share code, notes, and snippets.

@Couto
Last active June 6, 2016 15:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Couto/5905674 to your computer and use it in GitHub Desktop.
Save Couto/5905674 to your computer and use it in GitHub Desktop.
Small snippet to detect global variables.
(function (global) {
'use strict';
var globals = [];
var iframe = document.createElement('iframe');
var cleanWindow;
iframe.src = 'about:blank';
iframe.style.display = 'none';
document.body.appendChild(iframe);
cleanWindow = Object.assign({}, iframe.contentWindow, iframe.contentDocument);
iframe.parentNode.removeChild(iframe);
globals = Object.keys(global)
.map(function (key) { if (!(key in cleanWindow) ) { return key; } })
.filter(function (val) { return !!val; })
.sort();
console.log(globals.length, globals);
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment