splat sobre objeto JavaScript (con nuevo)?
¿Cómo salpicar objetos sin usarCaracterísticas de ECMA6?
Intentofunction can(arg0, arg1) {
return arg0 + arg1;
}
function foo(bar, haz) {
this.bar = bar;
this.haz = haz;
}
myArgs = [1,2];
Concan
Solo puedo hacer:
can.apply(this, myArgs);
Al intentar confoo
:
new foo.apply(this, myArgs);
Me sale este error (porque estoy llamandonew
):
TypeError: function apply() { [native code] } is not a constructor