JavaScript 中有 Set 字面量吗?

2022-01-17 00:00:00 set javascript ecmascript-6

我可以用 new Set(),同样我可以使用 Array 或 Object 或 Boolean 或 Number 构造函数.

I can make a Set with new Set(), same way I can use the Array or Object or Boolean or Number constructors.

但是是否有一套文字语法,比如数组、对象、布尔值、数字等?

But is there a set literal syntax, like there is for arrays, objects, booleans, numbers etc?

推荐答案

正如其他人所指出的,目前还没有 Set(或 Map)字面量语法.在这个 ES 讨论线程 并在 以下 Twitter 讨论中.

As others have pointed out, there is no Set (or Map) literal syntax yet. There have been a few ideas floating around, in this ES Discuss Thread and in the following twitter discussion.

几个建议的语法示例:

const set = {<1, "two", false>}; // by Brendan Eich
const set = {. 1, "two", false .}; // by Axel Rauschmayer

不过,据我所知,目前还没有任何建议可以实施.

There are, as far as I can see, no proposals to implement any of them yet, though.

相关文章