JS_SameValue 编辑
This article covers features introduced in SpiderMonkey 1.8.1
Determines if two jsval
s are the same, as determined by the SameValue algorithm in ECMAScript 262, 5th edition.
SameValue slightly differs from strict equality (===
) in that +0
and -0
are not the same and in that NaN
is the same as NaN
. The SameValue algorithm is equivalent to the following JavaScript:
function SameValue(v1, v2)
{
if (v1 === 0 && v2 === 0)
return 1 / v1 === 1 / v2;
if (v1 !== v1 && v2 !== v2)
return true;
return v1 === v2;
}
Syntax
// Added in SpiderMonkey 45
bool
JS_SameValue(JSContext *cx, JS::Handle<JS::Value> v1, JS::Handle<JS::Value> v2,
bool *same);
// Obsolete since JSAPI 39
bool
JS_SameValue(JSContext *cx, jsval v1, jsval v2, bool *same);
Name | Type | Description |
---|---|---|
cx | JSContext * | Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext . |
v1 | JS::Handle<JS::Value> / jsval | The first value. |
v2 | JS::Handle<JS::Value> / jsval | The second value. |
Description
JS_SameValue
determines whether two values are the same, returning true
or false
accordingly. This method is infallible.
See Also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论