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
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Symbol.keyFor' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Symbol.keyFor' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 40 | (Yes) | 36.0 (36.0) | No support | No support | No support |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | No support | (Yes) | 36.0 (36.0) | No support | No support | No support |