Suppose we do something like this (as part of the construction of a Javascript object):
var foo = 3;
this.method = function () { alert(foo); };
Now a closure will be generated to make sure foo is retained and available for use in method. Is there a way to do introspection on the current closure?
What I'm looking for is a way to enumerate all the variables that are available inside method, which should include foo. Debug code like this would greatly help in debugging the binding of closures, but I have yet to find it. Is it possible to do this?