I would do this simply with Array.of()
. Array of has the ability to use it's context as a constructor.
NOTE 2 The of function is an intentionally generic factory method; it does not require that its this value be the Array constructor. Therefore it can be transferred to or inherited by other constructors that may be called with a single numeric argument.
So we may bind Array.of()
to a function and generate an array like object.
function dummy(){};_x000D_
var thingy = Array.of.apply(dummy,[1,2,3,4]);_x000D_
console.log(thingy);
_x000D_
By utilizing Array.of()
one can even do array sub-classing.