JavaScript 中有 Set 字面量吗? [英] Is there a Set literal in JavaScript?

查看:24
本文介绍了JavaScript 中有 Set 字面量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以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.

这篇关于JavaScript 中有 Set 字面量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆