Skip to content

Instantly share code, notes, and snippets.

@unruthless
Last active August 29, 2015 14:02
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 unruthless/b648d867f15e45ba92fc to your computer and use it in GitHub Desktop.
Save unruthless/b648d867f15e45ba92fc to your computer and use it in GitHub Desktop.
sniffs for global variables
/**
* Detect Globals
* @source https://github.com/sindresorhus/log-globals
*/
(function () {
'use strict';
function getIframe() {
var el = document.createElement('iframe');
el.style.display = 'none';
document.body.appendChild(el);
var win = el.contentWindow;
document.body.removeChild(el);
return win;
}
function detectGlobals() {
var iframe = getIframe();
var globals = Object.create(null);
for (var prop in window) {
if (!(prop in iframe)) {
globals[prop] = window[prop];
}
}
return globals;
}
console.log(detectGlobals());
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment