Is it possible to create a function enumerateScope()
that lists all properties (keys) of the current scope?
<script>
var a = "foo";
enumerateScope(); //all properties of global window object including 'a'
</script>
this is pretty easy, but what about this?
<script>
(function(){
var b = "bar";
enumerateScope(); //either only 'b' or all properties of global window object including 'b'
})();
</script>
The last case is what I am interested in. I don't want to change any code inside the anonymous / closure scope just like
(function(scope){scope.b = "bar";})(window);
Is there any way to achieve this?