改进对男女两性平等的深入测试 节点 和浏览器.
什么是"深爱"?
深处 Eql是一个模块,您可以用来确定两个对象是否"深度"平等,也就是说,它不是具有偏好平等性(a === b),这个模块会递归检查对象的密钥,直到它找到原始人来检查偏好平等. 在JavaScript中将更多关于平等的内容改为 关于 mdn 的比较操作员文章。 。 。 .
举例来说,如下:
1 === 1 // These are primitives, they hold the same reference - they are strictly equal
1 == '1' // These are two different primitives, through type coercion they hold the same value - they are loosely equal
{ a: 1 } !== { a: 1 } // These are two different objects, they hold different references and so are not strictly equal - even though they hold the same values inside
{ a: 1 } != { a: 1 } // They have the same type, meaning loose equality performs the same check as strict equality - they are still not equal.
var deepEql = require("deep-eql");
deepEql({ a: 1 }, { a: 1 }) === true // deepEql can determine that they share the same keys and those keys share the same values, therefore they are deeply equal!
安装
节点.js
deep-eql 可在 无。 。 。 .
$ npm install deep-eql
使用量
二. 主要出口 deep-eql 是可给予两个对象比较的函数。 它总是会返回一个布尔,可以用来确定两个对象是否非常等同.
规则
- 严格实现不可逆节点的平等
Object.is数字 :eql(NaN, NaN).should.be.true;eql(-0, +0).should.be.false;
- 所有拥有和继承的可拥有财产都被视为:
eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 1 } })).should.be.true;eql(Object.create({ foo: { a: 1 } }), Object.create({ foo: { a: 2 } })).should.be.false;
- 比较时
Error对象,仅限name, (中文(简体) ),message,以及code属性被考虑,而不论是否具有:eql(Error('foo'), Error('foo')).should.be.true;eql(Error('foo'), Error('bar')).should.be.false;eql(Error('foo'), TypeError('foo')).should.be.false;eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 42 })).should.be.true;eql(Object.assign(Error('foo'), { code: 42 }), Object.assign(Error('foo'), { code: 13 })).should.be.false;eql(Object.assign(Error('foo'), { otherProp: 42 }), Object.assign(Error('foo'), { otherProp: 13 })).should.be.true;
- 参数不是参数 :
eql([], arguments).should.be.false;eql([], Array.prototype.slice.call(arguments)).should.be.true;