Skip to content

Commit

Permalink
missing comma fixed the regexp test and also an implementation for ty…
Browse files Browse the repository at this point in the history
…peof "function"
  • Loading branch information
James Halliday committed Jun 3, 2011
1 parent b9d1110 commit fc23e4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ Traverse.prototype.deepEqual = function (obj) {
else if (x === y) {
// nop
}
else if (typeof y === 'object') {
else if (typeof x === 'function') {
if (x instanceof RegExp) {
// both regexps on account of the __proto__ check
if (x.toString() != y.toString()) notEqual();
}
}
else if (typeof x === 'object') {
if (x === null || y === null) {
if (x !== y) notEqual();
}
Expand All @@ -91,8 +97,9 @@ Traverse.prototype.deepEqual = function (obj) {
notEqual();
}
}
else if (x instanceof Date && y instanceof Date) {
if (x.getTime() !== y.getTime()) {
else if (x instanceof Date || y instanceof Date) {
if (!(x instanceof Date) || !(y instanceof Date)
|| x.getTime() !== y.getTime()) {
notEqual();
}
}
Expand Down
6 changes: 2 additions & 4 deletions test/equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ exports.deepInstances = function () {
));

assert.ok(traverse.deepEqual(
[ new RegExp('x') ]
[ /x/ ],
[ new RegExp('x') ], [ /x/ ],
'regexp instances are real regexps'
));

assert.ok(!traverse.deepEqual(
[ new RegExp(/./) ]
[ /../ ],
[ new RegExp(/./) ], [ /../ ],
'these regexps aren\'t the same'
));

Expand Down

0 comments on commit fc23e4f

Please sign in to comment.