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 ofvalue
is not a known ECMAScript type andvalue
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:
-
它支持检测外部值。
¥It has support for detecting an External value.
-
它将
null
检测为单独的类型,而 ECMAScripttypeof
将检测object
。¥It detects
null
as a separate type, while ECMAScripttypeof
would detectobject
.
如果 value
的类型无效,则返回错误。
¥If value
has a type that is invalid, an error is returned.