Make methods capable of accepting unlimited arguments consistently accept either individual arguments or arrays of arguments.

Former-commit-id: b9f0c744f79e74889323f4fd7f737d10acd32ada
This commit is contained in:
John-David Dalton
2013-01-14 01:11:46 -08:00
parent 0404c2266c
commit 6ba4778c1b
7 changed files with 318 additions and 237 deletions

View File

@@ -277,9 +277,11 @@
var assignIteratorOptions = {
'args': 'object, source, guard',
'top':
"var argsIndex = 0, argsLength = typeof guard == 'number' ? 2 : arguments.length;\n" +
'var args = concat.apply(arrayRef, arguments),\n' +
' argsIndex = 0,\n' +
" argsLength = typeof guard == 'number' ? 2 : args.length;\n" +
'while (++argsIndex < argsLength) {\n' +
' if ((iteratee = arguments[argsIndex])) {',
' if ((iteratee = args[argsIndex])) {',
'loop': 'result[index] = iteratee[index]',
'bottom': ' }\n}'
};
@@ -468,14 +470,14 @@
// create the function factory
var factory = Function(
'createCallback, hasOwnProperty, isString, objectTypes, ' +
'nativeKeys, propertyIsEnumerable',
'arrayRef, concat, createCallback, hasOwnProperty, isString, ' +
'objectTypes, nativeKeys, propertyIsEnumerable',
'return function(' + args + ') {\n' + (data) + '\n}'
);
// return the compiled function
return factory(
createCallback, hasOwnProperty, isString, objectTypes,
nativeKeys, propertyIsEnumerable
arrayRef, concat, createCallback, hasOwnProperty, isString,
objectTypes, nativeKeys, propertyIsEnumerable
);
}
@@ -599,8 +601,9 @@
/**
* Assigns own enumerable properties of source object(s) to the `destination`
* object. Subsequent sources will overwrite propery assignments of previous
* sources.
* object. Source objects may be specified as individual arguments or as arrays
* of source objects. Subsequent sources will overwrite propery assignments of
* previous sources.
*
* @static
* @memberOf _
@@ -851,14 +854,15 @@
/**
* Assigns own enumerable properties of source object(s) to the `destination`
* object for all `destination` properties that resolve to `null`/`undefined`.
* Once a property is set, additional defaults of the same property will be
* ignored.
* Source objects may be specified as individual arguments or as arrays of source
* objects. Once a property is set, additional defaults of the same property will
* be ignored.
*
* @static
* @memberOf _
* @category Objects
* @param {Object} object The destination object.
* @param {Object} [default1, default2, ...] The default objects.
* @param {Object} [source1, source2, ...] The source objects.
* @returns {Object} Returns the destination object.
* @example
*
@@ -1470,10 +1474,10 @@
/**
* Creates a shallow clone of `object` composed of the specified properties.
* Property names may be specified as individual arguments or as arrays of
* property names. If `callback` is passed, it will be executed for each property
* in the `object`, picking the properties `callback` returns truthy for. The
* `callback` is bound to `thisArg` and invoked with three arguments; (value, key, object).
* Property names may be specified as individual arguments or as arrays of property
* names. If `callback` is passed, it will be executed for each property in the
* `object`, picking the properties `callback` returns truthy for. The `callback`
* is bound to `thisArg` and invoked with three arguments; (value, key, object).
*
* @static
* @memberOf _
@@ -3029,7 +3033,8 @@
/**
* Binds methods on `object` to `object`, overwriting the existing method.
* If no method names are provided, all the function properties of `object`
* Method names may be specified as individual arguments or as arrays of method
* names. If no method names are provided, all the function properties of `object`
* will be bound.
*
* @static
@@ -3050,7 +3055,7 @@
* // => When the button is clicked, `this.label` will have the correct value
*/
function bindAll(object) {
var funcs = arguments,
var funcs = concat.apply(arrayRef, arguments),
index = funcs.length > 1 ? 0 : (funcs = functions(object), -1),
length = funcs.length;
@@ -3064,6 +3069,7 @@
/**
* Creates a function that is the composition of the passed functions,
* where each function consumes the return value of the function that follows.
* Functions may be specified as individual arguments or as arrays of functions.
* In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`.
* Each function is executed with the `this` binding of the composed function.
*
@@ -3081,7 +3087,7 @@
* // => 'hi: moe!'
*/
function compose() {
var funcs = arguments;
var funcs = concat.apply(arrayRef, arguments);
return function() {
var args = arguments,
length = funcs.length;