Skip to content

Instantly share code, notes, and snippets.

@h2non
Created February 14, 2014 21:47
Show Gist options
  • Save h2non/9010025 to your computer and use it in GitHub Desktop.
Save h2non/9010025 to your computer and use it in GitHub Desktop.
JavaScript constructor with dynamic arguments that behaves like using the "new" operator
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