Create a function simulated class, allow multiple inheritance

var mapping = {
constructor: function Foo() {},
method: function(){},
});

Foo = createClass(mapping);
Foo = createClass(base, mapping);
Foo = createClass([base1, base2, ...], mapping);

By Raymond Xie <rjfun.mobile@gmail.com>, 2016/1/26
function createClass() {
  var mixins, definition;
  switch(arguments.length) {
    case 0:
      throw new Error('class definition required');
      break;
    case 1:
      mixins = [];
      definition = arguments[0];
      break;
    default:
      mixins = arguments[0];
      definition = arguments[1];
      break;
  }

  var newclass = definition['constructor'];

  if(typeof newclass !== 'function')
    throw new Error('constructor function required');

  if(typeof newclass.name === 'string' && newclass.name.length === 0)
    throw new Error('constructor name required, it will be used as new class name');

  newclass.prototype = definition;
  newclass.prototype.instanceOf = instanceOf;
  newclass.prototype.Super = superMethod;

  // if no mixin given, just create a base class
  if(!mixins) return newclass;

  if(Array.isArray(mixins)) {
    // multi inheritance, if mixins is an array of base classes
    for(var i=mixins.length-1; i>=0; i--) {
      newclass = mixin(newclass, mixins[i]);
    }
    return newclass;

  } else {
    // single inheritance
    return mixin(newclass, mixins);
  }
}