Make the guard checks in _.assign and _.defaults more thorough.

This commit is contained in:
John-David Dalton
2014-01-09 08:43:52 -08:00
parent f99668f551
commit 60b7f504e6
6 changed files with 75 additions and 49 deletions

33
dist/lodash.compat.js vendored
View File

@@ -4517,6 +4517,9 @@
* binding of `thisArg` and prepends any additional `bind` arguments to those
* provided to the bound function.
*
* Note: Unlike native `Function#bind` this method does not set the `length`
* property of bound functions.
*
* @static
* @memberOf _
* @category Functions
@@ -4546,6 +4549,8 @@
* of method names. If no method names are provided all the function properties
* of `object` will be bound.
*
* Note: This method does not set the `length` property of bound functions.
*
* @static
* @memberOf _
* @category Functions
@@ -4674,6 +4679,8 @@
* remaining `func` arguments, and so on. The arity of `func` can be specified
* if `func.length` is not sufficient.
*
* Note: This method does not set the `length` property of curried functions.
*
* @static
* @memberOf _
* @category Functions
@@ -4982,6 +4989,9 @@
* `partial` arguments prepended to those provided to the new function. This
* method is similar to `_.bind` except it does **not** alter the `this` binding.
*
* Note: This method does not set the `length` property of partially applied
* functions.
*
* @static
* @memberOf _
* @category Functions
@@ -5003,6 +5013,9 @@
* This method is like `_.partial` except that `partial` arguments are
* appended to those provided to the new function.
*
* Note: This method does not set the `length` property of partially applied
* functions.
*
* @static
* @memberOf _
* @category Functions
@@ -5137,10 +5150,10 @@
* defaults(object, { 'name': 'fred', 'employer': 'slate' });
* // => { 'name': 'barney', 'employer': 'slate' }
*/
function assign(object, source, guard) {
function assign(object, source) {
var args = arguments,
argsIndex = 0,
argsLength = typeof guard == 'number' ? 2 : args.length;
argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length;
if (argsLength > 3 && typeof args[argsLength - 2] == 'function') {
var callback = baseCreateCallback(args[--argsLength - 1], args[argsLength--], 2);
@@ -5306,8 +5319,6 @@
* @category Objects
* @param {Object} object The destination object.
* @param {...Object} [source] The source objects.
* @param- {Object} [guard] Allows working with `_.reduce` without using its
* `key` and `object` arguments as sources.
* @returns {Object} Returns the destination object.
* @example
*
@@ -5315,10 +5326,10 @@
* _.defaults(object, { 'name': 'fred', 'employer': 'slate' });
* // => { 'name': 'barney', 'employer': 'slate' }
*/
function defaults(object, source, guard) {
function defaults(object, source) {
var args = arguments,
argsIndex = 0,
argsLength = typeof guard == 'number' ? 2 : args.length;
argsLength = args[3] && args[3][args[2]] === source ? 2 : args.length;
while (++argsIndex < argsLength) {
source = args[argsIndex];
@@ -5854,8 +5865,8 @@
/**
* Checks if `value` is, or can be coerced to, a finite number.
*
* Note: This is not the same as native `isFinite` which will return true for
* booleans and empty strings. See the [ES5 spec](http://es5.github.io/#x15.1.2.5)
* Note: This method is not the same as native `isFinite` which will return
* `true` for booleans and empty strings. See the [ES5 spec](http://es5.github.io/#x15.1.2.5)
* for more details.
*
* @static
@@ -5938,8 +5949,8 @@
/**
* Checks if `value` is `NaN`.
*
* Note: This is not the same as native `isNaN` which will return `true` for
* `undefined` and other non-numeric values. See the [ES5 spec](http://es5.github.io/#x15.1.2.4)
* Note: This method is not the same as native `isNaN` which will return `true`
* for `undefined` and other non-numeric values. See the [ES5 spec](http://es5.github.io/#x15.1.2.4)
* for more details.
*
* @static
@@ -6379,7 +6390,7 @@
}
/**
* An alternative to `_.reduce` this method transforms `object` to a new
* An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own
* enumerable properties through a callback, with each callback execution
* potentially mutating the `accumulator` object. The callback is bound to