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);
					

参数

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 .

范例

Using keyFor

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.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
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

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: