Skip to content

Instantly share code, notes, and snippets.

@Raynos
Created September 23, 2011 12:20
Show Gist options
  • Save Raynos/1237213 to your computer and use it in GitHub Desktop.
Save Raynos/1237213 to your computer and use it in GitHub Desktop.
var new = function _new(Constructor) {
var thisObj = Object.create(Constructor.prototype);
var args = Array.prototype.slice.call(arguments, 1);
var retObj = Constructor.apply(thisObj, args);
if (typeof retObj === "object") {
return retObj;
} else {
return thisObj
}
};
var F = function() { };
F.prototype.a = 42;
var o = new(F);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment