top | item 26319295 (no title) sethx | 5 years ago Please elaborate about toString() ? discuss order hn newest jffry|5 years ago The toString() method returns a string representing the source code of the function.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Dragonai|5 years ago That's pretty neat. Thanks for the link. byroot|5 years ago If called on a Function it returns the source of the function, which allows for all sorts of meta programming. hajile|5 years ago If memory serves, a real world example was Angular doing a toString then injecting dependencies before calling eval on the new code.To be honest, I don’t know that there’s ever a good reason to use it in production as it almost always involves performance and security problems. load replies (2) junon|5 years ago Yep. We used to use this for some hacks back before AST libraries were a thing, mainly because Function.prototype.toString() preserves comments.function foo() { /* a comment! / }console.log(foo.toString()); //-> "function foo() { / a comment! */ }"
jffry|5 years ago The toString() method returns a string representing the source code of the function.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... Dragonai|5 years ago That's pretty neat. Thanks for the link.
byroot|5 years ago If called on a Function it returns the source of the function, which allows for all sorts of meta programming. hajile|5 years ago If memory serves, a real world example was Angular doing a toString then injecting dependencies before calling eval on the new code.To be honest, I don’t know that there’s ever a good reason to use it in production as it almost always involves performance and security problems. load replies (2) junon|5 years ago Yep. We used to use this for some hacks back before AST libraries were a thing, mainly because Function.prototype.toString() preserves comments.function foo() { /* a comment! / }console.log(foo.toString()); //-> "function foo() { / a comment! */ }"
hajile|5 years ago If memory serves, a real world example was Angular doing a toString then injecting dependencies before calling eval on the new code.To be honest, I don’t know that there’s ever a good reason to use it in production as it almost always involves performance and security problems. load replies (2)
junon|5 years ago Yep. We used to use this for some hacks back before AST libraries were a thing, mainly because Function.prototype.toString() preserves comments.function foo() { /* a comment! / }console.log(foo.toString()); //-> "function foo() { / a comment! */ }"
jffry|5 years ago
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
Dragonai|5 years ago
byroot|5 years ago
hajile|5 years ago
To be honest, I don’t know that there’s ever a good reason to use it in production as it almost always involves performance and security problems.
junon|5 years ago
function foo() { /* a comment! / }
console.log(foo.toString()); //-> "function foo() { / a comment! */ }"