Created
May 3, 2009 02:17
-
-
Save silentmatt/105796 to your computer and use it in GitHub Desktop.
Call a constructor with an array of arguments (apply for constructors)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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