Compare errors by identity in _.isEqual
Author: randymCreated Oct 8, 2020Updated Nov 25, 2020
Labelsbreaking changestarter
Edit bij @jgonggrijp: tldr link.
Is this intentional?
var a = new Error('a')
var b = new Error('b')
_.isEqual(a, b) // trueThis holds true for extensions as well...
class A extends Error { constructor(message) { super(message); this.enumerable = 'Klaatu barada nikto' } }
var e1 = new A('Fear has been substituted for reason.')
var e2 = new A('Join us and live in peace')
_.isEqual(a, b) // trueOther built in types (e.g. Date, RegExp, Symbol) have various methods to coerce for comparison. Error comparison ends up in deep equality comparison, which relies on Object.keys and ends up comparing empty arrays.
Happy to send in a PR if this is unintentional, also happy to work around it if it is.
Source: jashkenas/underscore