Skip to content

Commit 430ded4

Browse files
committed
Add a message to TypeError from _.bind
1 parent 6ddd517 commit 430ded4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

test/functions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
equal(newBoundf.hello, undefined, 'function should not be bound to the context, to comply with ECMAScript 5');
3939
equal(Boundf().hello, 'moe curly', "When called without the new operator, it's OK to be bound to the context");
4040
ok(newBoundf instanceof F, 'a bound instance is an instance of the original function');
41+
42+
raises(
43+
function() { _.bind('notafunction'); },
44+
function(actual) { return actual instanceof TypeError && actual.message !== ''; },
45+
'throws an error when binding to a non-function'
46+
);
4147
});
4248

4349
test('partial', function() {

underscore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@
600600
_.bind = function(func, context) {
601601
var args, bound;
602602
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
603-
if (!_.isFunction(func)) throw new TypeError;
603+
if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
604604
args = slice.call(arguments, 2);
605605
return bound = function() {
606606
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));

0 commit comments

Comments
 (0)