text: import * as _ from "./utils";
  
  export function mix(def) {
      var composed = {
          init: [],
          preEmit: [],
          shouldEmit: []
      };
  
  //立即执行函数，代码运行到这里之后，马上运行该函数，【注意一下，传入的参数mixin，经由ifff函数def传入】
      var updated = (function mixDef(mixin) {
          var mixed = {};
          if (mixin.mixins) {
              mixin.mixins.forEach(function (subMixin) {
                  //递归，调用自己，防止函数中还有函数？js代码一样飘逸
                  _.extend(mixed, mixDef(subMixin));
              });
          }
          _.extend(mixed, mixin);
          Object.keys(composed).forEach(function (composable) {
              if (mixin.hasOwnProperty(composable)) {
                  composed[composable].push(mixin[composable]);
              }
          });
          return mixed;
      }(def));
  
      if (composed.init.length > 1) {
          updated.init = function () {
              var args = arguments;
              composed.init.forEach(function (init) {
                  init.apply(this, args);
              }, this);
          };
      }
      if (composed.preEmit.length > 1) {
          updated.preEmit = function () {
              return composed.preEmit.reduce(function (args, preEmit) {
                  var newValue = preEmit.apply(this, args);
                  return newValue === undefined ? args : [newValue];
              }.bind(this), arguments);
          };
      }
      if (composed.shouldEmit.length > 1) {
          updated.shouldEmit = function () {
              var args = arguments;
              return !composed.shouldEmit.some(function (shouldEmit) {
                  return !shouldEmit.apply(this, args);
              }, this);
          };
      }
      Object.keys(composed).forEach(function (composable) {
          if (composed[composable].length === 1) {
              updated[composable] = composed[composable][0];
          }
      });
  
      return updated;
  }
  