makery.js
function createInstanceOf(ctor, args) {
    var tempCtor = function() {
      // This will return the instance or the explicit return of the ctor
      // accordingly.
      // Remember that if you return a primitive type, the constructor will
      // still return the object instance.
      return ctor.apply(this, args);
    };

    tempCtor.prototype = ctor.prototype;
    return new tempCtor();
  }
function createInstanceOf(ctor, args) {
    var tempCtor = function() {
      // This will return the instance or the explicit return of the ctor
      // accordingly.
      // Remember that if you return a primitive type, the constructor will
      // still return the object instance.
      return ctor.apply(this, args);
    };

    tempCtor.prototype = ctor.prototype;
    return new tempCtor();
  }
function createInstanceOf ( ctor , args ) { var tempCtor = function ( ) { // This will return the instance or the explicit return of the ctor // accordingly. // Remember that if you return a primitive type, the constructor will // still return the object instance. return ctor . apply ( this , args ) ; } ; tempCtor . prototype = ctor . prototype ; return new tempCtor ( ) ; }
We need a custom creation of an instance because we cannot pass a dynamic amount of args into a constructor when calling them with "new", so we must first call it with a fake constructor with the same prototype and then apply the real one with the correct args.
We need a custom creation of an instance because we cannot pass a dynamic amount of args into a constructor when calling them with new so we must first call it with a fake constructor with the same prototype and then apply the real one with the correct args .