-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Objects with null prototype cause fast-deep-equal to throw an error #49
Comments
I believe it is not recommended In JS to have objects with null prototype (even though it is technically possible) - What is the reason to use them (and to support in this library)? See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create Mozilla here recommends as the best solution to resolving the problems of objects created with null prototype ... setting their prototype to Object. Not quite sure why null prototype was allowed in the first place, as using such objects creates more problems than null prototype can potentially solve (although I’m still not quite sure which problems can be solved with it). |
I don't use null prototype directly, but Some quick issue searching shows some reasoning for using null prototype. |
Thank you - I commented there. The design decision here is to consider instances of different classes (i.e. with different prototypes in JS) as not equal, even if they have the same properties. So if I am also considering to introduce a version of this function that ignores classes/prototypes and only checks properties, with some specific exceptions (e.g. Date and RegExp). To address it now, any possible workaround should be used in the application code. |
Same issue if A has fastDeepEqual({}, { valueOf: 'foo' }); // success
fastDeepEqual({ valueOf: 'foo' }, {}); // error
Uncaught TypeError: a.valueOf is not a function Is |
We are running into the same issue (also using
Fair enough. Would it make sense to consider |
Tangential but relevant: Array.prototype.group, which is on standards track, is spec'd to return objects with no prototype. I'd find it surprising if objects from such a builtin method were to cause a crash in fast-deep-equal. |
Example code:
This will throw an error, the line below calls
.valueOf()
which is not a method for objects with a null prototype.https://github.com/epoberezkin/fast-deep-equal/blob/master/src/index.jst#L51
The text was updated successfully, but these errors were encountered: