javascript - Get all variables of the current function() scope -
i'm having problem. want current function scrope. have example code i'm working ok.
function nittle(){ var pen = new dot(); // generated dynamical through eval() ..... for(key in window) { if( window[key] instanceof dot ){ alert("found it"); } } }
but seems not work within function scope. work outside of it. there work around ?
thanks.
i'm not aware of way determine programmatically variables have been declared inside function, except perhaps use nittle.tostring()
, attempting parse find variables. maybe work you? (but it's messy me attempt here.) update: if variables created via eval()
won't work, you'd see eval()
statement in function's string representation.
is there work around ?
you declare single object in function , change variables properties of object:
function nittle() { var nittlevars = { var1 : "something", pen : new dot(), etc : "whatever" }; (var key in nittlevars){ if( nittlevars[key] instanceof dot ){ alert("found it"); } } }
your update indicates variables created eval()
- still object properties idea:
eval("nittlevars.newvar = new dot()"); // inside function
Comments
Post a Comment