问题描述
什么是SymbolJavaScript类型?
引用规范:
我以为对象键只是字符串,我并不孤单要引用:
可以解释符号类型是什么,并展示其用法。我试图理解这个规范。
谢谢!
我认为对象键只是字符串
你是对的,但是对于只有EcmaScript 5。 ES 6 /和谐是一个新的东西的草稿!
这只是草稿,。如何使用符号以及是否或如何通过任意脚本创建它们似乎还没有解决(请浏览进行更改。
如果向下滚动到(甚至在附件F以下),例如,您将看到一个第8.4.4节:符号外来物体那已经搬到那里了它表示
您可以在。对于 Symbol
构造函数的建议使用(和仍然存在的问题/公开问题),请查看 页面或。
What is the "Symbol" javascript type as mentioned in this ECMAScript 6 draft specification?
To quote the spec:
I thought object keys were strings only, and I'm not alone. To quote this accepted SO answer:
Could you explain what the symbol type is, and demonstrate its usage. I'm trying to make sense of the spec.
Thanks!
You're right, but that was true for EcmaScript 5 only. ES 6 / harmony is a draft for something new!
It's a draft only, rapidly changing. How symbols are used and whether or how they can be created by arbitrary scripts does not seem to have settled yet (scan through the versions for changes).
If you scroll down to the very end of that document (even below Annex F), you for example will see a Section 8.4.4: Symbol Exotic Objects that has been moved out there. It states
You can see them used at section 8.1.7.4 Well-Known Symbols and Intrinsics for example. For proposed uses (and still existing problems / open questions) of Symbol
constructors have a look at these strawman pages or this wiki site.
这篇关于JavaScript符号类型:(非字符串对象键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!