Created
September 23, 2011 12:20
-
-
Save Raynos/1237213 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
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