diff --git a/lodash.js b/lodash.js index 7ea8a37d9..e0690b2fd 100644 --- a/lodash.js +++ b/lodash.js @@ -7790,7 +7790,7 @@ function createCallback(func, thisArg, argCount) { var type = typeof func; if (type == 'function' || func == null) { - return (typeof thisArg == 'undefined' || !('prototype' in func)) && + return (typeof thisArg == 'undefined' || !(func && 'prototype' in func)) && func || baseCreateCallback(func, thisArg, argCount); } // handle "_.pluck" and "_.where" style callback shorthands diff --git a/test/test.js b/test/test.js index a335bd74b..33e531d61 100644 --- a/test/test.js +++ b/test/test.js @@ -1663,6 +1663,18 @@ }); }); + test('should not error when `func` is nullish and a `thisArg` is provided', 2, function() { + var object = {}; + _.each([null, undefined], function(value) { + try { + var callback = _.callback(value, {}); + strictEqual(callback(object), object); + } catch(e) { + ok(false); + } + }); + }); + test('should return a callback created by `_.matches` when `func` is an object', 2, function() { var callback = _.callback({ 'a': 1 }); strictEqual(callback({ 'a': 1, 'b': 2 }), true);