Skip to content

Instantly share code, notes, and snippets.

@silentmatt
Created May 3, 2009 02:17
Show Gist options
  • Save silentmatt/105796 to your computer and use it in GitHub Desktop.
Save silentmatt/105796 to your computer and use it in GitHub Desktop.
Call a constructor with an array of arguments (apply for constructors)
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
function firefox_construct(constructor, args) {
var o = {};
o.__proto__ = constructor.prototype;
var res = constructor.apply(o, args);
if (typeof res !== "undefined") {
return res;
}
return o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment