napi_typeof


napi_status napi_typeof(napi_env env, napi_value value, napi_valuetype* result) 
  • [in] env:调用 API 的环境。

    ¥[in] env: The environment that the API is invoked under.

  • [in] value:要查询其类型的 JavaScript 值。

    ¥[in] value: The JavaScript value whose type to query.

  • [out] result:JavaScript 值的类型。

    ¥[out] result: The type of the JavaScript value.

如果 API 成功,则返回 napi_ok

¥Returns napi_ok if the API succeeded.

  • 如果 value 的类型不是已知的 ECMAScript 类型并且 value 不是外部值,则为 napi_invalid_arg

    ¥napi_invalid_arg if the type of value is not a known ECMAScript type and value is not an External value.

此 API 表示类似于在 ECMAScript 语言规范的 第 12.5.5 节 中定义的对象上调用 typeof 运算符的行为。但是,存在一些差异:

¥This API represents behavior similar to invoking the typeof Operator on the object as defined in Section 12.5.5 of the ECMAScript Language Specification. However, there are some differences:

  1. 它支持检测外部值。

    ¥It has support for detecting an External value.

  2. 它将 null 检测为单独的类型,而 ECMAScript typeof 将检测 object

    ¥It detects null as a separate type, while ECMAScript typeof would detect object.

如果 value 的类型无效,则返回错误。

¥If value has a type that is invalid, an error is returned.