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_argif the type ofvalueis not a known ECMAScript type andvalueis not an External value.
此 API 表示类似于在 ECMAScript 语言规范的 typeof 运算符部分 中定义的对象上调用 typeof 运算符的行为。但是,存在一些差异:
¥This API represents behavior similar to invoking the typeof Operator on
the object as defined in Section typeof operator of the ECMAScript Language
Specification. However, there are some differences:
-
它支持检测外部值。
¥It has support for detecting an External value.
-
它将
null检测为单独的类型,而 ECMAScripttypeof将检测object。¥It detects
nullas a separate type, while ECMAScripttypeofwould detectobject.
如果 value 的类型无效,则返回错误。
¥If value has a type that is invalid, an error is returned.