diff --git a/test/objects.js b/test/objects.js index 187c69d13..236a9d955 100644 --- a/test/objects.js +++ b/test/objects.js @@ -342,6 +342,9 @@ $(document).ready(function() { ok(_.isEqual(isEqualObjClone, isEqualObj), 'Commutative equality is implemented for objects with custom `isEqual` methods'); ok(!_.isEqual(isEqualObj, {}), 'Objects that do not implement equivalent `isEqual` methods are not equal'); ok(!_.isEqual({}, isEqualObj), 'Commutative equality is implemented for objects with different `isEqual` methods'); + + // Objects from another frame. + ok(_.isEqual({}, iObject)); }); test("isEmpty", function() { @@ -378,6 +381,7 @@ $(document).ready(function() { parent.iNull = null;\ parent.iBoolean = new Boolean(false);\ parent.iUndefined = undefined;\ + parent.iObject = {};\ " ); iDoc.close(); diff --git a/underscore.js b/underscore.js index c47f47c84..705277d15 100644 --- a/underscore.js +++ b/underscore.js @@ -847,8 +847,13 @@ } } } else { - // Objects with different constructors are not equivalent. - if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; + // Objects with different constructors are not equivalent, but `Object`s + // from different frames are. + var aCtor = a.constructor, bCtor = b.constructor; + if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && + _.isFunction(bCtor) && (bCtor instanceof bCtor))) { + return false; + } // Deep compare objects. for (var key in a) { if (_.has(a, key)) {