I referenced this particular solution to create a new instance of a class by passing array arguments using the code snippet below:
new ( Cls.bind.apply( Cls, arguments ) )();
However, I encountered an issue where one of my arguments is an array and the values are not preserved during construction.
You can see an example illustrating this problem in this CodePen demo
In the demo, I pass an array named properties
as the third argument:
var properties = [
{ name: "first", value: "1" },
{ name: "second", value: "2" },
{ name: "third", value: "3" }
];
Yet, in the output, the properties are shown as undefined
.
It seems like there is an error occurring somewhere in the process, but what exactly is going wrong and why?