Skip to content

Commit

Permalink
[Refactor] objEquiv: bail early if typeofs are different
Browse files Browse the repository at this point in the history
  • Loading branch information
KoryNunn authored and ljharb committed Sep 23, 2014
1 parent 0c5b21a commit 410e2d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function isBuffer(x) {
function objEquiv(a, b, opts) {
/* eslint max-statements: [2, 50] */
var i, key;
if (typeof a !== typeof b) { return false; }
if (isUndefinedOrNull(a) || isUndefinedOrNull(b)) { return false; }

// an identical 'prototype' property.
Expand Down
12 changes: 12 additions & 0 deletions test/cmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,15 @@ test('arrays and objects', function (t) {

t.end();
});

test('functions', function (t) {
function f() {}

t.ok(equal(f, f), 'a function is equal to itself');
t.ok(equal(f, f, { strict: true }), 'strict: a function is equal to itself');

t.notOk(equal(function () {}, function () {}), 'two different functions are never equal');
t.notOk(equal(function () {}, function () {}, { strict: true }), 'strict: two different functions are never equal');

t.end();
});

0 comments on commit 410e2d6

Please sign in to comment.