Issue #150: _.bind should allow binding functions to falsy values.

This commit is contained in:
Kit Goncharov
2011-03-20 09:36:00 -06:00
parent 59ef91ee80
commit 4869b4c6ca
2 changed files with 7 additions and 2 deletions

View File

@@ -20,10 +20,15 @@ $(document).ready(function() {
var func = _.bind(func, this, 'curly');
equals(func(), 'hello: curly', 'the function was completely applied in advance');
var func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname };
func = _.bind(func, this, 'hello', 'moe', 'curly');
equals(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments');
func = function(context, message) { equals(this, context, message); };
_.bind(func, 0, 0, 'can bind a function to `0`')();
_.bind(func, '', '', 'can bind a function to an empty string')();
_.bind(func, false, false, 'can bind a function to `false`')();
});
test("functions: bindAll", function() {

View File

@@ -412,7 +412,7 @@
if (nativeBind && func.bind === nativeBind) return func.bind.apply(func, slice.call(arguments, 1));
var args = slice.call(arguments, 2);
return function() {
return func.apply(obj || {}, args.concat(slice.call(arguments)));
return func.apply(obj, args.concat(slice.call(arguments)));
};
};