dimanche 29 mars 2015

In Node.js, how do I inspect the local variables of a function?

How to see the locals of a function?


eg here, I can see that it is going to return a+b, but if its coming from a lib somewhere, then I have no idea what those things are:



fn = function() {
var a=123, b=456;
return function() { return a + b; };
}();


For comparison, here is how I would do it in Ruby:



fn = lambda do
a, b = 123, 456
lambda { a + b }
end.call

fn.binding.local_variable_get(:a) # => 123
fn.binding.local_variable_get(:b) # => 456


I'm willing to switch to io.js if it can give me this kind of ability to reflect on the system.






Aucun commentaire:

Enregistrer un commentaire