1 var arrayEach = require('./_arrayEach'),
2 arrayPush = require('./_arrayPush'),
3 baseFunctions = require('./_baseFunctions'),
4 copyArray = require('./_copyArray'),
5 isFunction = require('./isFunction'),
6 isObject = require('./isObject'),
7 keys = require('./keys');
10 * Adds all own enumerable function properties of a source object to the
11 * destination object. If `object` is a function then methods are added to
12 * its prototype as well.
14 * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
15 * avoid conflicts caused by modifying the original.
20 * @param {Function|Object} [object=lodash] The destination object.
21 * @param {Object} source The object of functions to add.
22 * @param {Object} [options] The options object.
23 * @param {boolean} [options.chain=true] Specify whether the functions added
25 * @returns {Function|Object} Returns `object`.
28 * function vowels(string) {
29 * return _.filter(string, function(v) {
30 * return /[aeiou]/i.test(v);
34 * _.mixin({ 'vowels': vowels });
38 * _('fred').vowels().value();
41 * _.mixin({ 'vowels': vowels }, { 'chain': false });
45 function mixin(object, source, options) {
46 var props = keys(source),
47 methodNames = baseFunctions(source, props);
49 var chain = (isObject(options) && 'chain' in options) ? options.chain : true,
50 isFunc = isFunction(object);
52 arrayEach(methodNames, function(methodName) {
53 var func = source[methodName];
54 object[methodName] = func;
56 object.prototype[methodName] = function() {
57 var chainAll = this.__chain__;
58 if (chain || chainAll) {
59 var result = object(this.__wrapped__),
60 actions = result.__actions__ = copyArray(this.__actions__);
62 actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
63 result.__chain__ = chainAll;
66 return func.apply(object, arrayPush([this.value()], arguments));
74 module.exports = mixin;