Last active
August 29, 2015 14:02
-
-
Save unruthless/b648d867f15e45ba92fc to your computer and use it in GitHub Desktop.
sniffs for global variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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