Symbol.keyFor(sym)
method retrieves a shared symbol key from the global symbol registry for the given symbol.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Symbol.keyFor(sym);
Symbol, required. The symbol to find a key for.
A string representing the key for the given symbol if one is found on the global registry; otherwise,
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
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Symbol.keyFor' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keyFor
|
Chrome 40 | Edge 12 | Firefox 36 | IE No | Opera 27 | Safari 9 | WebView Android 40 | Chrome Android 40 | Firefox Android 36 | Opera Android 27 | Safari iOS 9 | Samsung Internet Android 4.0 | nodejs 0.12 |
完整支持
不支持
Symbol
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()