artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
mixin.js
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');
8 
45 function mixin(object, source, options) {
46  var props = keys(source),
47  methodNames = baseFunctions(source, props);
48 
49  var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
50  isFunc = isFunction(object);
51 
52  arrayEach(methodNames, function(methodName) {
53  var func = source[methodName];
54  object[methodName] = func;
55  if (isFunc) {
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__);
61 
62  actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
63  result.__chain__ = chainAll;
64  return result;
65  }
66  return func.apply(object, arrayPush([this.value()], arguments));
67  };
68  }
69  });
70 
71  return object;
72 }
73 
74 module.exports = mixin;