在 javascript 中具有数值属性的数组和对象是否相等?
Are arrays and objects with numeric properties equal in javascript?
谁能给我解释一下为什么以下是正确的:
let foo = {
A: [ 1, 2 ]
}
let bar = {
"A": {
"0": "1",
"1": "2"
}
}
assert.deepEqual(foo, bar);
正如the documentation所说:
Only enumerable "own" properties are considered. The assert.deepEqual()
implementation does not test the [[Prototype]]
of objects or enumerable own Symbol
properties. For such checks, consider using assert.deepStrictEqual()
instead.
assert.deepStrictEqual()
函数也检查原型,
assert.deepStrictEqual(foo, bar);
将 return 错误。
谁能给我解释一下为什么以下是正确的:
let foo = {
A: [ 1, 2 ]
}
let bar = {
"A": {
"0": "1",
"1": "2"
}
}
assert.deepEqual(foo, bar);
正如the documentation所说:
Only enumerable "own" properties are considered. The
assert.deepEqual()
implementation does not test the[[Prototype]]
of objects or enumerable ownSymbol
properties. For such checks, consider usingassert.deepStrictEqual()
instead.
assert.deepStrictEqual()
函数也检查原型,
assert.deepStrictEqual(foo, bar);
将 return 错误。