News for hackers. Stuff that matters.
Re:jQuery 3.6.0 by sethx on Tuesday March 02, 2021 @02:25PM (#26319295)
Please elaborate about toString() ?
Re:jQuery 3.6.0 by jffry on Tuesday March 02, 2021 @02:39PM (#26319518)
The toString() method returns a string representing the source code of the function.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re:jQuery 3.6.0 by Dragonai on Tuesday March 02, 2021 @03:08PM (#26319908)
That's pretty neat. Thanks for the link.
Re:jQuery 3.6.0 by byroot on Tuesday March 02, 2021 @02:27PM (#26319326)
If called on a Function it returns the source of the function, which allows for all sorts of meta programming.
Re:jQuery 3.6.0 by hajile on Tuesday March 02, 2021 @02:50PM (#26319662)
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.

Re:jQuery 3.6.0 by davidmurdoch on Tuesday March 02, 2021 @03:15PM (#26319994)
> involves performance [...] problems

Except when it solves them! https://mrale.ph/blog/2018/02/03/maybe-you-dont-need-rust-to...

Re:jQuery 3.6.0 by postalrat on Tuesday March 02, 2021 @10:35PM (#26324414)
I once used it for a proof of concept for computer worm type message on a sort of message board. Used to re-generate the source code to be added to new messages.
Re:jQuery 3.6.0 by junon on Wednesday March 03, 2021 @03:52AM (#26326123)
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! */ }"