src/libs/Module.js
function addPropertiesAndMethodsToModule(sModuleId, aDependencies, fpCallback) {
  var oPromise;

  function success(mapping) {
    const oModules = getModules();
    var oModule, fpInitProxy;
    oModule = oModules[sModuleId].creator.apply(oModules[sModuleId], [].slice.call(arguments, 1));
    oModule.__children__ = [];
    oModule.dependencies = aDependencies || [].slice.call(arguments, 1);
    oModule.resolvedDependencies = mapping;
    oModule.__module_id__ = sModuleId;
    fpInitProxy = oModule.init || nullFunc;
    // Provide compatibility with old versions of Hydra.js
    oModule.__action__ = oModule.__sandbox__ = Bus;
    oModule.events = oModule.events || {};
    oModule.init = function () {
      var aArgs = copyArray(arguments).concat(getVars());
      if (oModule.__children__.length === 0) {  // Only subscribe last element of inheritance.
        Bus.subscribe(oModule);
      }
      return fpInitProxy.apply(this, aArgs);
    };
    oModule.handleAction = function (oNotifier) {
      var fpCallback = this.events[oNotifier.type];
      if (isTypeOf(fpCallback, sNotDefined)) {
        return;
      }
      fpCallback.call(this, oNotifier);
    };
    // Provide compatibility with old Hydra versions which used to use "destroy" as onDestroy hook.
    oModule.onDestroy = oModule.onDestroy || oModule.destroy || function () {
      };
    oModule.destroy = function () {
      this.onDestroy();
      Bus.unsubscribe(oModule);
      delete oModules[sModuleId].instances[oModule.__instance_id__];
    };
    fpCallback(oModule);
  }

  oPromise = resolveDependencies(sModuleId, aDependencies);
  oPromise.then(function () {
    success.apply(success, arguments);
  });
}
function addPropertiesAndMethodsToModule(sModuleId, aDependencies, fpCallback) {
  var oPromise;

  function success(mapping) {
    const oModules = getModules();
    var oModule, fpInitProxy;
    oModule = oModules[sModuleId].creator.apply(oModules[sModuleId], [].slice.call(arguments, 1));
    oModule.__children__ = [];
    oModule.dependencies = aDependencies || [].slice.call(arguments, 1);
    oModule.resolvedDependencies = mapping;
    oModule.__module_id__ = sModuleId;
    fpInitProxy = oModule.init || nullFunc;
    // Provide compatibility with old versions of Hydra.js
    oModule.__action__ = oModule.__sandbox__ = Bus;
    oModule.events = oModule.events || {};
    oModule.init = function () {
      var aArgs = copyArray(arguments).concat(getVars());
      if (oModule.__children__.length === 0) {  // Only subscribe last element of inheritance.
        Bus.subscribe(oModule);
      }
      return fpInitProxy.apply(this, aArgs);
    };
    oModule.handleAction = function (oNotifier) {
      var fpCallback = this.events[oNotifier.type];
      if (isTypeOf(fpCallback, sNotDefined)) {
        return;
      }
      fpCallback.call(this, oNotifier);
    };
    // Provide compatibility with old Hydra versions which used to use "destroy" as onDestroy hook.
    oModule.onDestroy = oModule.onDestroy || oModule.destroy || function () {
      };
    oModule.destroy = function () {
      this.onDestroy();
      Bus.unsubscribe(oModule);
      delete oModules[sModuleId].instances[oModule.__instance_id__];
    };
    fpCallback(oModule);
  }

  oPromise = resolveDependencies(sModuleId, aDependencies);
  oPromise.then(function () {
    success.apply(success, arguments);
  });
}
Add common properties and methods to avoid repeating code in modules
@param {String} sModuleId
@param {Array} aDependencies
@param {Function} fpCallback
@private