* Adds function properties of a source object to the destination object. * If `object` is a function methods will be added to its prototype as well. * * @static * @memberOf _ * @category Utilities * @param {Function|Object} [object=lodash] object The destination object.
(object, source, options)
| 41026 | * // => 'Fred' |
| 41027 | */ |
| 41028 | function mixin(object, source, options) { |
| 41029 | var chain = true, |
| 41030 | methodNames = source && functions(source); |
| 41031 | |
| 41032 | if (!source || (!options && !methodNames.length)) { |
| 41033 | if (options == null) { |
| 41034 | options = source; |
| 41035 | } |
| 41036 | ctor = lodashWrapper; |
| 41037 | source = object; |
| 41038 | object = lodash; |
| 41039 | methodNames = functions(source); |
| 41040 | } |
| 41041 | if (options === false) { |
| 41042 | chain = false; |
| 41043 | } else if (isObject(options) && 'chain' in options) { |
| 41044 | chain = options.chain; |
| 41045 | } |
| 41046 | var ctor = object, |
| 41047 | isFunc = isFunction(ctor); |
| 41048 | |
| 41049 | forEach(methodNames, function(methodName) { |
| 41050 | var func = object[methodName] = source[methodName]; |
| 41051 | if (isFunc) { |
| 41052 | ctor.prototype[methodName] = function() { |
| 41053 | var chainAll = this.__chain__, |
| 41054 | value = this.__wrapped__, |
| 41055 | args = [value]; |
| 41056 | |
| 41057 | push.apply(args, arguments); |
| 41058 | var result = func.apply(object, args); |
| 41059 | if (chain || chainAll) { |
| 41060 | if (value === result && isObject(result)) { |
| 41061 | return this; |
| 41062 | } |
| 41063 | result = new ctor(result); |
| 41064 | result.__chain__ = chainAll; |
| 41065 | } |
| 41066 | return result; |
| 41067 | }; |
| 41068 | } |
| 41069 | }); |
| 41070 | } |
| 41071 | |
| 41072 | /** |
| 41073 | * Reverts the '_' variable to its previous value and returns a reference to |
no test coverage detected