Skip to content

Commit 0a5c5c2

Browse files
committed
Merge pull request #5 from dougluce/master
Different objects aren't the same
2 parents c866adf + dfbb670 commit 0a5c5c2

3 files changed

Lines changed: 29 additions & 3 deletions

File tree

lib/eql.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ catch(ex) {
2121
Buffer.isBuffer = function() { return false; }
2222
}
2323

24+
/*!
25+
* For browsers that don't support Object.getPrototypeOf (IE8?)
26+
*/
27+
28+
function _getProto(object) {
29+
if (typeof Object.getPrototypeOf === 'function') {
30+
return Object.getPrototypeOf(object);
31+
} else if (''.__proto__ === String.prototype) {
32+
return object.__proto__;
33+
} else {
34+
return object.constructor.prototype;
35+
}
36+
}
37+
2438
/*!
2539
* Primary Export
2640
*/
@@ -213,7 +227,7 @@ function objectEqual(a, b, m) {
213227
return false;
214228
}
215229

216-
if (a.prototype !== b.prototype) {
230+
if (_getProto(a) !== _getProto(b)) {
217231
return false;
218232
}
219233

test/bootstrap/karma.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
global.assert = require('simple-assert');
2-
global.eql = require('deep-eql');
1+
assert = require('simple-assert');
2+
eql = require('deep-eql');

test/eql.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ tests.push([ 'eql([], [])', [], [] ]);
2121
tests.push([ 'eql({}, {})', {}, {} ]);
2222
tests.push([ 'eql([], {})', [], {}, true ]);
2323

24+
/*!
25+
* object identity
26+
*/
27+
28+
function Base1() {};
29+
function Base2() {};
30+
var object1 = new Base1();
31+
var object2 = new Base2();
32+
33+
tests.push([ 'eql(object1, object1)', object1, object1 ]);
34+
tests.push([ 'eql(object1, object2)', object1, object2, true ]);
35+
2436
(function() {
2537
tests.push([ 'eql([], arguments)', [], arguments, true ]);
2638
})();

0 commit comments

Comments
 (0)