greepow greepow - 1 year ago 89
Javascript Question

How to get function body text in JavaScript?

function derp() { a(); b(); c(); }

will return
"function derp() { a(); b(); c(); }"
, but I only need the body of the function, so
"a(); b(); c();"
, because I can then evaluate the expression. Is it possible to do this in a cross-browser way?

Answer Source
var entire = derp.toString(); 
var body = entire.slice(entire.indexOf("{") + 1, entire.lastIndexOf("}"));

print(body); // "a(); b(); c();"

Please use the search, this is duplicate of this question

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download