node_api_symbol_for


napi_status node_api_symbol_for(napi_env env,
                                const char* utf8description,
                                size_t length,
                                napi_value* result) 
  • [in] env:调用该 API 时所处的环境。
  • [in] utf8description:UTF-8 C 字符串,表示将用作符号描述的文本。
  • [in] length:描述字符串的字节长度,如果是以 null 结尾,则为 NAPI_AUTO_LENGTH
  • [out] result:一个表示 JavaScript symbolnapi_value

如果 API 成功,则返回 napi_ok

【Returns napi_ok if the API succeeded.】

此 API 会在全局注册表中搜索具有给定描述的现有符号。如果符号已存在,将返回该符号;否则,将在注册表中创建一个新符号。

【This API searches in the global registry for an existing symbol with the given description. If the symbol already exists it will be returned, otherwise a new symbol will be created in the registry.】

JavaScript 的 symbol 类型在 ECMAScript 语言规范的 章节符号类型 中有描述。

【The JavaScript symbol type is described in Section symbol type of the ECMAScript Language Specification.】