Skip to content

Commit

Permalink
bindAll throws a reference error if a given method is undefined on th…
Browse files Browse the repository at this point in the history
…e incoming object
  • Loading branch information
smarden1 committed Jun 19, 2014
1 parent ac647af commit 900511c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@

raises(function() { _.bindAll(moe); }, Error, 'throws an error for bindAll with no functions named');

raises(function() { _.bindAll(moe, "sayBye"); }, ReferenceError, 'throws an error for bindAll if the given function is undefined');

_.bindAll(moe, 'sayHi', 'sayLast');
curly.sayHi = moe.sayHi;
equal(curly.sayHi(), 'hi: moe');
Expand Down
1 change: 1 addition & 0 deletions underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@
if (length <= 1) throw Error('bindAll must be passed function names');
for (; i < length; i++) {
key = arguments[i];
if (_.isUndefined(obj[key])) throw ReferenceError(key + " is not defined");
obj[key] = createCallback(obj[key], obj, Infinity);
}
return obj;
Expand Down

0 comments on commit 900511c

Please sign in to comment.