Created
March 10, 2011 05:49
-
-
Save GarrettS/863633 to your computer and use it in GitHub Desktop.
newApply
This file contains 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 F(){} | |
function newApply(ctor, args) { | |
var i, | |
fp = F.prototype = ctor.prototype; // Copy prototype. | |
if(fp) { | |
fp.constructor = ctor; | |
} | |
i = new F; | |
ctor.apply(i, args); // Apply the original constructor. | |
return i; | |
} | |
// Example: | |
function Cat(a, b){ | |
this.a = a; | |
this.b = b; | |
} | |
newApply(Cat, [1,2]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment