-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
How to compare Object.create()? #620
Comments
see nodejs/node-v0.x-archive#4523
obviously, it had to be /cc @iojs/owners |
I'm alright with fixing it. |
@vkurchatkin thanks, great work. |
Objects with different prototypes should not be considered deep equal, e.g. `assert.deepEqual({}, [])` should throw. Previously `deepEqual` was implemented as per CommonJS Unit Testing/1.0 spec. It states that objects should have 'an identical "prototype" property' to be considered deep equal, which is incorrect. Instead object prototypes should be compared, i.e. `Object.getPrototypeOf` or `__proto__`. Fixes: nodejs#620
`deepStrictEqual` works the same way as `strictEqual`, but uses `===` to compare primitives and requires prototypes of equal objects to be the same object. Fixes: nodejs/node-v0.x-archive#7161 Fixes: #620 PR-URL: #639 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-by: Rod Vagg <rod@vagg.org>
you can use |
Thanks, great. |
I just noticed that this does NOT throw: assert.deepEqual(Object.create({tea:'chai'}), Object.create({tea:'black'})) Weird. |
@jokeyrhyme use |
Using
Object.create
method to create object.How to compare them for equality or deep equality?
Use
Object.getPrototypeOf
?e.g.
The text was updated successfully, but these errors were encountered: