audibleblink
8/19/2014 - 2:54 AM

Reimplementation of the `new` keyword as a function

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
}