在线文档教程

Symbol.keyFor

Symbol.keyFor

Symbol.keyFor(sym) 方法用来获取 symbol 注册表中与某个 symbol 关联的键。

语法

Symbol.keyFor(sym

参数

sym存储在 symbol 注册表中的某个 symbol

返回值

如果在全局注册表中找到,则表示给定符号的键的字符串; 否则返回undefined

示例

var globalSym = Symbol.for('foo' // create a new global symbol Symbol.keyFor(globalSym // "foo" var localSym = Symbol( Symbol.keyFor(localSym // undefined // well-known symbols are not symbols registered // in the global symbol registry Symbol.keyFor(Symbol.iterator) // undefined

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Symbol.keyFor' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Symbol.keyFor' in that specification.Draft

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support40(Yes)36.0 (36.0)No supportNo supportNo support

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo supportNo support(Yes)36.0 (36.0)No supportNo supportNo support