Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reimplementation of the `new` keyword as a function
var newNew = function(constructor, args) {
var instance = Object.create(constructor.prototype)
// instance.__proto__ = constructor.prototype // Same as line above
instance.constructor = constructor // So that you can see who created this.
constructor.apply(instance, args) // Same as #call except args is an arrray with apply
return instance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment