Let's say that I want to get a list of all the variables in the window
that are user-defined. In other words, they're not properties or objects that the browser has created or defined in ECMAScript.
For example, let's say there's this script on a page:
<script>
window.__$DEBUG = true;
var Analytics = function() {};
</script>
I would like to be able to loop through window
and get a list containing __$DEBUG
and its value, and Analytics
and its value:
var nonNatives = (function nonNative(scope) {
var result = {};
for (var child in scope) {
if (!isNative(child)) {
result[child] = scope[child];
}
}
return result;
})(window);
Can this be done?