Es6-symbol-keyfor

提供:Dev Guides
2020年6月23日 (火) 08:04時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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