Skip to content

Instantly share code, notes, and snippets.

@GarrettS
Created March 10, 2011 05:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GarrettS/863633 to your computer and use it in GitHub Desktop.
Save GarrettS/863633 to your computer and use it in GitHub Desktop.
newApply
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