Skip to content

Commit

Permalink
Check function lengths as well for equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 14, 2014
1 parent 0169b55 commit e944591
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ module.exports = function isEqual(value, other) {
}

if (type === funcType) {
return isEqual(value.name, other.name) && isEqual(String(value), String(other));
if (!isEqual(value.name, other.name)) { return false; }
if (!isEqual(value.length, other.length)) { return false; }

return isEqual(String(value), String(other));
}

if (type === objType) {
Expand Down
3 changes: 3 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ test('functions', function (t) {
var anon1 = function () { /* ANONYMOUS! */ };
var anon2 = function () { /* ANONYMOUS! */ };

var anon1withArg = function (a) { /* ANONYMOUS! */ };

t.ok(isEqual(f1, f1), 'same function is equal to itself');
t.ok(isEqual(anon1, anon1), 'same anon function is equal to itself');
t.notOk(isEqual(anon1, anon1withArg), 'similar anon function with different lengths are not equal');

t.notOk(isEqual(f1, g), 'functions with different names but same implementations are not equal');
t.ok(isEqual(f1, f2), 'functions with same names but same implementations are equal');
Expand Down

0 comments on commit e944591

Please sign in to comment.