Why is my function undefined?
<p>I'm new to javascript. I have coded the following:</p>

<pre><code>function Vec2(x_,y_)
{
    this.x = x_;
    this.y = y_;
}
</code></pre>

<p>Later in the file I create a function like this:</p>

<pre><code>// Init game field array
var initGameField = function () {
    var screenCenter = vec2(canvas.width / 2, canvas.height / 2);
    var index = 0;

    // Init gamefieldArray
    for(var y = 0; y &lt; maxVerticalBubbles; y++)
    {
        if(y%2)
        {
            for(var x = 0; x &lt; maxHorizontalBubbles - 1; x++)
            {
                var initPoint = vec2(cellSize / 2 + (screenCenter.x - ((maxVerticalBubbles - 1) * cellSize / 2)) + (x * cellSize), 
                                 canvas.height / 2 + (cellSize / 2) + y * cellSize / 1.1);

                gameFieldArray[index] = initPoint;
            }
        }
        else
        {
            for(var x = 0; x &lt; maxHorizontalBubbles; x++)
        {
                var initPoint = vec2(cellSize / 2 + (screenCenter.x - (maxVerticalBubbles * cellSize / 2)) + (x * cellSize), 
                                 canvas.height / 2 + (cellSize / 2) + y * cellSize / 1.1);

                gameFieldArray[index] = initPoint;
            }
        }
    }
}
</code></pre>

<p>But when I try to run the initGameField function at the end of the javascript -file I get errors on "vec2 not defined" inside "initGameField"... How should this be done the right way? Why isn't the function vec2 recognized since it has been introduced before initGameField -function and before running initGameField -function?</p>
