Skip to content

Instantly share code, notes, and snippets.

@odiak
Created July 19, 2011 13:26
Show Gist options
  • Save odiak/1092316 to your computer and use it in GitHub Desktop.
Save odiak/1092316 to your computer and use it in GitHub Desktop.
Function.prototype.applyNew = function (args) {
var that = new Object(), res;
if (typeof args !== "object" || args.constructor !== Array) {
args = [];
}
if (typeof this.prototype === "object") {
that.__proto__ = this.prototype;
}
res = this.apply(that, args);
return (typeof res === "object") ? res : that;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment