Created
February 14, 2014 21:47
-
-
Save h2non/9010025 to your computer and use it in GitHub Desktop.
JavaScript constructor with dynamic arguments that behaves like using the "new" operator
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 MyClass(/* dynamic constructor arguments, meta-programming rules! */) {} | |
MyClass.prototype.method = function () {} | |
MyClass.create = function () { | |
var instance = Object.create(MyClass.prototype) | |
MyClass.apply(instance, arguments) | |
return instance | |
} | |
MyClass.create('string', 123, false, undefined, void) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment