# JavaScript 无括号调用函数的新玩法

Original title: Yet another way to invoke functions without parentheses

> Hacker News story 50077225 · language: zh · submitted 2026-10-13
> Web version: https://zeli.app/zh/story/50077225
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 265 · by [aragonite](<https://news.ycombinator.com/user?id=aragonite>) · 💬 106
[original](<https://blog.ikaes.de/yet-another-way-to-invoke-functions-without-parentheses/>) · [HN discussion](<https://news.ycombinator.com/item?id=50077225>)

## Summary

我发现了一种在 JavaScript 中无需括号即可调用任意函数的新技巧。其核心原理是利用 Error 对象的 prepareStackTrace 函数来生成自定义代码，该函数通常在访问错误堆栈时被触发。由于堆栈本质上是数组，我通过覆盖 Array.prototype.toString 方法，将其转换为特定的 JavaScript 代码片段。结合原型污染技术，我成功操控了 Error.prototype.toString 的输出。最后，利用 valueOf 技巧将生成的对象作为原语调用，从而实现了无括号执行。这一系列操作展示了 JavaScript 引擎机制的巧妙利用，为代码执行提供了全新的视角。

## Key quote

> 我确信还有更多方法可以实现这一目标。

## HN discussion (106 comments)

### [hans_castorp](<https://news.ycombinator.com/item?id=50116896>)

> 这让我想起了那个“创作者承认 Unix 和 C 是骗局”的梗（例如 https://www.gnu.org/fun/jokes/unix-hoax.html）
>
> \> 当我们能用以下语法成功编译时，我们就停手了：
>
> for(;P("\n"),R--;P("|"))for(e=C;e--;P("_"+(*u++/8)%2))P("| "+(*u/4)%2);

### [nathell](<https://news.ycombinator.com/item?id=50116963>)

> 我太爱这个了。这是个有趣的黑客技巧，但这篇文章也让人回想起 LLM 出现之前的日子，那时人们还对 _代码_ 本身充满兴趣。

### [MattCruikshank](<https://news.ycombinator.com/item?id=50118596>)

> 我想写一本超级较真的书，展示我能想到的所有将数据从 A 处移动到 B 处的方法。无论是在同一个程序内，还是在不同程序之间。
>
> 全局变量。
>
> 函数的参数。
>
> 传入一个函子/lambda，然后获取值。
>
> 环境变量。
>
> 注册表。
>
> 文件。
>
> 把它存在 ping 响应里。
>
> 写入然后读取的 VRAM 纹理。
>
> 数据库。
>
> REST 服务器。
>
> 我敢肯定我能想出上千种方法。
>
> 但是……为什么？我为什么要写这本书？为什么这件事一直萦绕在我心头？

### [amelius](<https://news.ycombinator.com/item?id=50117797>)

> 我想把被调用的函数放在参数后面：
>
> (((x)f)g)h
>
> 这样我就能从左到右清楚地看到事情发生的顺序。
>
> 而不是：
>
> f(g(h(x)))
>
> 那样我不得不倒着读。

### [CrendKing](<https://news.ycombinator.com/item?id=50117115>)

> 在 Firefox 上行不通，因为根据文档，Error.prepareStackTrace 是一个可选 API，且仅由 V8 实现。

### [pards](<https://news.ycombinator.com/item?id=50116791>)

> 题外话：这个网站看起来像勒索信。

### [TheSilva](<https://news.ycombinator.com/item?id=50116732>)

> Object.prototype.message='alert\x281337\x29';Array.prototype.toString=Error.prototype.toString;Error.prepareStackTrace = Function;const x = new Error;x.valueOf=x.stack;+x;
>
> 哇，这真是一长串！这么多年过去了，JavaScript 依然能在编程世界里做出最惊人、最怪异、最酷、最吓人、最晦涩也最性感的操作。

### [semiquaver](<https://news.ycombinator.com/item?id=50116740>)

> JavaScript 真是被诅咒了。

---

## Cite

- Page: https://zeli.app/zh/story/50077225
- Date: 2026-10-13
- Source: blog.ikaes.de (https://blog.ikaes.de/yet-another-way-to-invoke-functions-without-parentheses/)
- Hacker News: https://news.ycombinator.com/item?id=50077225

## Other languages

- en: https://zeli.app/story/50077225 · markdown: https://zeli.app/story/50077225.md
- ja: https://zeli.app/ja/story/50077225 · markdown: https://zeli.app/ja/story/50077225.md
- ko: https://zeli.app/ko/story/50077225 · markdown: https://zeli.app/ko/story/50077225.md
- de: https://zeli.app/de/story/50077225 · markdown: https://zeli.app/de/story/50077225.md
- es: https://zeli.app/es/story/50077225 · markdown: https://zeli.app/es/story/50077225.md
- ru: https://zeli.app/ru/story/50077225 · markdown: https://zeli.app/ru/story/50077225.md
