Should I use prototype or not?
<p>I'm creating a Vector class, which can basically hold three numerical values. However, a lot of operations can be done on such a vector - e.g. getting the magnitude, adding or subtracting another vector etc.</p>

<p>I was wondering whether these functions should be coded as being a prototype function of the Vector class, or that I should define them in the constructor.</p>

<p>So which of these two methods is preferable?</p>

<pre><code>function Vector3D(x, y, z) {
    this.x = x;
    this.y = y
    this.z = z;
}

Vector3D.prototype.magnitude = function() {
    return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
};
</code></pre>

<p>or</p>

<pre><code>function Vector3D(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;

    this.magnitude = function() {
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    };
}
</code></pre>
