If I have a JavaScript function and I want to call it by passing a list of arguments, I use apply
:
var x = f(1,2,3);
var x = f.apply(null, [1,2,3]);
For the first time, I came across a case where I need to call a constructor with a list of arguments, and the first thing I tried (even though I suspected it was going to go wrong) was simply same:
var x = new f(1,2,3);
var x = new f.apply(null, [1,2,3]);
And it did not really work ... Is there any way to do this? I have to create several objects in a loop, and I was forced to do so:
var x = new f(lista[0], lista[1], lista[2]);
That's not so bad in the case of a constructor with only 3 parameters, but I wonder if there is a more concise or "smart" way.