splat sobre objeto JavaScript (com novo)?
Como faço para dividir objetos sem usarRecursos do ECMA6?
Tentativafunction can(arg0, arg1) {
return arg0 + arg1;
}
function foo(bar, haz) {
this.bar = bar;
this.haz = haz;
}
myArgs = [1,2];
Comcan
Eu posso apenas fazer:
can.apply(this, myArgs);
Ao tentar comfoo
:
new foo.apply(this, myArgs);
Eu recebo esse erro (porque estou ligandonew
):
TypeError: function apply() { [native code] } is not a constructor