Skip to content

Commit

Permalink
Two symbols are equal by valueOf(). Closes jashkenas#2450
Browse files Browse the repository at this point in the history
  • Loading branch information
akre54 committed Feb 29, 2016
1 parent 8edea87 commit 723aaff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@
assert.equal(_.isEqual({a: 0}, {a: -0}), false);
assert.equal(_.isEqual([NaN], [NaN]), true);
assert.equal(_.isEqual({a: NaN}, {a: NaN}), true);

if (typeof Symbol !== 'undefined') {
var symbol = Symbol('x');
assert.strictEqual(_.isEqual(symbol, symbol), true, 'A symbol is equal to itself');
assert.strictEqual(_.isEqual(symbol, Object(symbol)), true, 'Even when wrapped in Object()');
assert.strictEqual(_.isEqual(symbol, null), false, 'Different types are not equal');
}

});

QUnit.test('isEmpty', function(assert) {
Expand Down
3 changes: 3 additions & 0 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

// Save bytes in the minified (but not gzipped) version:
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;

// Create quick reference variables for speed access to core prototypes.
var push = ArrayProto.push,
Expand Down Expand Up @@ -1195,6 +1196,8 @@
// millisecond representations. Note that invalid dates with millisecond representations
// of `NaN` are not equivalent.
return +a === +b;
case '[object Symbol]':
return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
}

var areArrays = className === '[object Array]';
Expand Down

0 comments on commit 723aaff

Please sign in to comment.