mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 08:57:49 +00:00
_.bind should throw a TypeError if func is not a function. [closes #213]
Former-commit-id: b6035736d9cb042b7fa4a9d0b7b4d9c6cb0ea4f8
This commit is contained in:
16
lodash.js
16
lodash.js
@@ -144,7 +144,8 @@
|
||||
Number = context.Number,
|
||||
Object = context.Object,
|
||||
RegExp = context.RegExp,
|
||||
String = context.String;
|
||||
String = context.String,
|
||||
TypeError = context.TypeError;
|
||||
|
||||
/** Used for `Array` and `Object` method references */
|
||||
var arrayRef = Array(),
|
||||
@@ -650,19 +651,24 @@
|
||||
* @param {Function|String} func The function to bind or the method name.
|
||||
* @param {Mixed} [thisArg] The `this` binding of `func`.
|
||||
* @param {Array} partialArgs An array of arguments to be partially applied.
|
||||
* @param {Object} [rightIndicator] Used to indicate partially applying arguments from the right.
|
||||
* @param {Object} [idicator] Used to indicate binding by key or partially
|
||||
* applying arguments from the right.
|
||||
* @returns {Function} Returns the new bound function.
|
||||
*/
|
||||
function createBound(func, thisArg, partialArgs, rightIndicator) {
|
||||
function createBound(func, thisArg, partialArgs, indicator) {
|
||||
var isFunc = isFunction(func),
|
||||
isPartial = !partialArgs,
|
||||
key = thisArg;
|
||||
|
||||
// juggle arguments
|
||||
if (isPartial) {
|
||||
var rightIndicator = indicator;
|
||||
partialArgs = thisArg;
|
||||
}
|
||||
if (!isFunc) {
|
||||
else if (!isFunc) {
|
||||
if (!indicator) {
|
||||
throw new TypeError;
|
||||
}
|
||||
thisArg = func;
|
||||
}
|
||||
|
||||
@@ -4268,7 +4274,7 @@
|
||||
* // => 'hi, moe!'
|
||||
*/
|
||||
function bindKey(object, key) {
|
||||
return createBound(object, key, slice(arguments, 2));
|
||||
return createBound(object, key, slice(arguments, 2), indicatorObject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user