For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/year/2025/proposal-set-methods.md.
  • 简体中文
  • New Set methods S4

    中文标题:新的 Set 方法

    提案概览
    提案速览

    该提案为 JavaScript 内置的 Set 原型添加了像 union、intersection 和 difference 等集合操作方法,解决了无需第三方库即可进行常见集合操作的需求。它规定了七个方法,所有方法都要求参数具有数值 size 属性以及 keys 和 has 方法。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    JavaScript 的 Set 方法

    这是一个向 JavaScript 内置 Set 类添加像 union 和 intersection 等方法的提案。

    目前处于第 4 阶段:它已被添加到规范中。此仓库已不再活跃。

    以下是原始 README。

    提案

    该提案将添加以下方法:

    • Set.prototype.intersection(other)
    • Set.prototype.union(other)
    • Set.prototype.difference(other)
    • Set.prototype.symmetricDifference(other)
    • Set.prototype.isSubsetOf(other)
    • Set.prototype.isSupersetOf(other)
    • Set.prototype.isDisjointFrom(other)

    这些方法都要求其参数是一个 Set,或者至少是一个看起来像 Set 的东西,即具有数值 size 属性以及 keys 和 has 方法。

    有关此提案中当前决策的详细信息,请参阅 details.md。

    渲染后的规范文本可在此处获取。

    该提案最初由 Michał Wadas 编写,后来由 Sathya Gunasekaran 和 Kevin Gibbons 主导。

    实现

    此提案已可供引擎实现并发布。有关当前状态,请参阅此问题。

    TC39 会议记录

    (半)相关的先前讨论

    与其他语言的比较

    请参阅其他语言文档以了解其他语言中 Set 方法的概览。

    命名

    有关详细信息,请参阅命名讨论文档。

    我们决定选择:

    • 对称差集 - symmetricDifference
    • 交集 - intersection
    • 并集 - union
    • 差集 - difference

    Polyfills