Skip to content

Instantly share code, notes, and snippets.

Created December 18, 2012 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4326703 to your computer and use it in GitHub Desktop.
Save anonymous/4326703 to your computer and use it in GitHub Desktop.
function Bit(a, b) {
this.a = a;
this.b = b;
}
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
var one = new Bit(1, 2);
var two = construct(Bit, [1, 2]);
@joshnesbitt
Copy link

It would be nice also if you could use construct without the explicit array, like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment