Skip to content

Instantly share code, notes, and snippets.

@narqo
Created October 8, 2014 23:13
Show Gist options
  • Save narqo/185dbeaae87504f7da5f to your computer and use it in GitHub Desktop.
Save narqo/185dbeaae87504f7da5f to your computer and use it in GitHub Desktop.
function Ctor(param1, param2, param3) {
this._param1 = param1;
this._param2 = param2;
this._param3 = param3;
}
Ctor.create = function(p1, p2, p3) {
return new this(p1, p2, p3);
}
Ctor.factroy = function() {
var instance = Object.create(Ctor.prototype);
return Ctor.apply(instance, arguments) || instance;
}
var c = Ctor.create(1, 2, 3);
console.log('c', c, c.create);
console.assert(c instanceof Ctor);
var cf = Ctor.factroy(1, 2, 3);
console.log('cf', cf, cf.create);
console.assert(cf instanceof Ctor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment