Option name | Type | Description |
---|---|---|
Constructor | Function | The prototype you wish to instantiate |
args | Any | The arguments to |
return | Object | new instance of |
Simulates calling new MyConstructor
with dynamic args
module.exports = function dynamicNew(Constructor, args) {
var result = Object.create(Constructor.prototype)
if(!result) {
throw new Error('Could not dynamically new ' + toString.call(Constructor))
}
Constructor.apply(result,args || [])
return result
}