This describes a JavaScript technique to execute arbitrary functions without using parentheses by abusing the Error object's stack formatting hook. The prepareStackTrace callback, normally used to format stack traces, has the same parameter signature as the Function constructor: when an error's stack is accessed, prepareStackTrace receives an array-like "structured stack" whose second argument can be treated as code by Function. By redirecting prepareStackTrace to Function, a generated function can be produced from the stack trace machinery instead of from an explicit constructor call.
To make the stack-derived array yield executable code, the array-to-string conversion is controlled. That is achieved either by overwriting Array.prototype.toString or by exploiting prototype pollution to influence Error.prototype.toString via Object.prototype.message, so the stack array’s string becomes the desired JavaScript payload. Finally, the generated function is invoked by coercing the Error object - e.g., replacing its valueOf (or toString and concatenating) so that a unary + triggers execution. The post shows this end-to-end sequence and provides a ready-to-run browser-console example demonstrating function creation and invocation without parentheses.
Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.