Can Javascript get a function as text?
问题 Can Javascript get a function as text? I'm thinking like the inverse of eval(). function derp() { a(); b(); c(); } alert(derp.asString()); The result would be something like "a(); b(); c();" Does it exist? 回答1: Updated to include caveats in the comments below from CMS, Tim Down, MooGoo: The closest thing available to what you're after is calling .toString() on a function to get the full function text, like this: function derp() { a(); b(); c(); } alert(derp.toString()); //"function derp() { a