Applies an array of arguments to an object constructor, ensuring the constructor is called with a new
keyword.
Because you can't do:
var foo = new Foo.apply(ohLordWhatDoIPassHere, arguments);
With component(1):
component install darsain/constructor-apply
var constructorApply = require('constructor-apply');
function Foo(a, b) {
this.a = a;
this.b = b;
}
Foo.prototype.log = function () {
console.log(this.a, this.b);
};
var fooObject = constructorApply(Foo, [1, 2]);
foo instanceof Foo; // true
foo.log(); // logs: 1 2
Will call a custructor with a new
keyword and apply arguments to it.
Constructor Type Function
Object constructor.
arguments Type Array
Array of arguments.
Returns
New Constructor instance/object.
MIT