Es6-symbol-keyfor
提供:Dev Guides
ES6-Symbol.keyFor
このメソッドは、指定されたシンボルのグローバルシンボルレジストリから共有シンボルキーを取得します。
構文
Symbol.keyForの構文については以下で説明します。symはキーを検索するための記号です。
Symbol.keyFor(sym)
例
<script>
const user_Id = Symbol.for('userId')//creates a new Symbol in registry
console.log(Symbol.keyFor(user_Id))//returns the key of a symbol in registry
const userId = Symbol("userId")//symbol not in registry
console.log(Symbol.keyFor(userId))//userId symbol is not in registry
</script>
コードの出力は以下のとおりです-
userId
undefined