Suppose I have a long javascript function such as
function test() {
var x;
var a;
...
...
...
...
...
}
is there any way I can ask the function itself to tell me what variables were defined so far.
function test() {
var x;
var a;
...
...
...
...
... // bit of code that would say to me: x and a.
}
No, not without relying on
Function#toStringand then performing string processing on the result, which is not recommend.Function#toStringis implemented by most browsers as giving you the source code of the function (with or without comments, depending), but isn’t standardized by the spec (even the latest) and I wouldn’t use it in production code.