mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
import bindCallback from './bindCallback';
|
|
import isIterateeCall from './isIterateeCall';
|
|
|
|
/**
|
|
* Creates a function that assigns properties of source object(s) to a given
|
|
* destination object.
|
|
*
|
|
* @private
|
|
* @param {Function} assigner The function to assign values.
|
|
* @returns {Function} Returns the new assigner function.
|
|
*/
|
|
function createAssigner(assigner) {
|
|
return function() {
|
|
var args = arguments,
|
|
length = args.length,
|
|
object = args[0];
|
|
|
|
if (length < 2 || object == null) {
|
|
return object;
|
|
}
|
|
var customizer = args[length - 2],
|
|
thisArg = args[length - 1],
|
|
guard = args[3];
|
|
|
|
if (length > 3 && typeof customizer == 'function') {
|
|
customizer = bindCallback(customizer, thisArg, 5);
|
|
length -= 2;
|
|
} else {
|
|
customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null;
|
|
length -= (customizer ? 1 : 0);
|
|
}
|
|
if (guard && isIterateeCall(args[1], args[2], guard)) {
|
|
customizer = length == 3 ? null : customizer;
|
|
length = 2;
|
|
}
|
|
var index = 0;
|
|
while (++index < length) {
|
|
var source = args[index];
|
|
if (source) {
|
|
assigner(object, source, customizer);
|
|
}
|
|
}
|
|
return object;
|
|
};
|
|
}
|
|
|
|
export default createAssigner;
|