Initializing a javascript object containing an array
<p>I have the following C++ struct which I want to create as faithfully as possible in Javascript:</p>

<pre><code>struct Vertex
{
   float coords[4];
   float colors[4];
};
</code></pre>

<p>So I did the following:</p>

<pre><code>function Vertex(coords, colors)
{
   this.coords = [];
   this.colors = [];
}
</code></pre>

<p>Now, the following works to create a Vertex instance:</p>

<pre><code>var oneVertex = new Vertex();
oneVertex.coords = [20.0, 20.0, 0.0, 1.0];
oneVertex.colors = [0.0, 0.0, 0.0, 1.0];
</code></pre>

<p>but the following (slicker?) doesn't:</p>

<pre><code>var oneVertex = new Vertex([20.0, 20.0, 0.0, 1.0], 
                            [0.0, 0.0, 0.0, 1.0]);
</code></pre>

<p>Why? I am new to Javascript and what little I have read suggests it should be ok. Obviously not. It would be helpful to understand what I am missing. Thanks.</p>