mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Issue #150: _.bind should allow binding functions to falsy values.
This commit is contained in:
@@ -24,6 +24,11 @@ $(document).ready(function() {
|
|||||||
var func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname };
|
var func = function(salutation, firstname, lastname) { return salutation + ': ' + firstname + ' ' + lastname };
|
||||||
func = _.bind(func, this, 'hello', 'moe', 'curly');
|
func = _.bind(func, this, 'hello', 'moe', 'curly');
|
||||||
equals(func(), 'hello: moe curly', 'the function was partially applied in advance and can accept multiple arguments');
|
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() {
|
test("functions: bindAll", function() {
|
||||||
|
|||||||
@@ -412,7 +412,7 @@
|
|||||||
if (nativeBind && func.bind === nativeBind) return func.bind.apply(func, slice.call(arguments, 1));
|
if (nativeBind && func.bind === nativeBind) return func.bind.apply(func, slice.call(arguments, 1));
|
||||||
var args = slice.call(arguments, 2);
|
var args = slice.call(arguments, 2);
|
||||||
return function() {
|
return function() {
|
||||||
return func.apply(obj || {}, args.concat(slice.call(arguments)));
|
return func.apply(obj, args.concat(slice.call(arguments)));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user