util.isDeepStrictEqual(val1, val2[, options])
-
val1
<any> -
val2
<any> -
skipPrototype
<boolean> 如果是true
,则在深度严格相等性检查期间跳过原型和构造函数比较。默认值:false
。¥
skipPrototype
<boolean> Iftrue
, prototype and constructor comparison is skipped during deep strict equality check. Default:false
. -
返回:<boolean>
¥Returns: <boolean>
如果 val1
和 val2
之间存在深度严格相等,则返回 true
。否则,返回 false
。
¥Returns true
if there is deep strict equality between val1
and val2
.
Otherwise, returns false
.
默认情况下,深度严格相等性包括对象原型和构造函数的比较。当 skipPrototype
等于 true
时,如果对象的可枚举属性严格相等,则即使具有不同的原型或构造函数,它们仍可被视为相等。
¥By default, deep strict equality includes comparison of object prototypes and
constructors. When skipPrototype
is true
, objects with
different prototypes or constructors can still be considered equal if their
enumerable properties are deeply strictly equal.
const util = require('node:util');
class Foo {
constructor(a) {
this.a = a;
}
}
class Bar {
constructor(a) {
this.a = a;
}
}
const foo = new Foo(1);
const bar = new Bar(1);
// Different constructors, same properties
console.log(util.isDeepStrictEqual(foo, bar));
// false
console.log(util.isDeepStrictEqual(foo, bar, true));
// true
有关深度严格相等的更多信息,请参见 assert.deepStrictEqual()
。
¥See assert.deepStrictEqual()
for more information about deep strict
equality.