Created
July 19, 2011 13:26
-
-
Save odiak/1092316 to your computer and use it in GitHub Desktop.
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.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