1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import arrayEach from './_arrayEach.js';
- import arrayPush from './_arrayPush.js';
- import baseFunctions from './_baseFunctions.js';
- import copyArray from './_copyArray.js';
- import isFunction from './isFunction.js';
- import isObject from './isObject.js';
- import keys from './keys.js';
- function mixin(object, source, options) {
- var props = keys(source),
- methodNames = baseFunctions(source, props);
- var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
- isFunc = isFunction(object);
- arrayEach(methodNames, function(methodName) {
- var func = source[methodName];
- object[methodName] = func;
- if (isFunc) {
- object.prototype[methodName] = function() {
- var chainAll = this.__chain__;
- if (chain || chainAll) {
- var result = object(this.__wrapped__),
- actions = result.__actions__ = copyArray(this.__actions__);
- actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
- result.__chain__ = chainAll;
- return result;
- }
- return func.apply(object, arrayPush([this.value()], arguments));
- };
- }
- });
- return object;
- }
- export default mixin;
|