Skip to content

Instantly share code, notes, and snippets.

@audibleblink
Created August 19, 2014 02:54
Show Gist options
  • Save audibleblink/583be9b750a0e40302ea to your computer and use it in GitHub Desktop.
Save audibleblink/583be9b750a0e40302ea to your computer and use it in GitHub Desktop.
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