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
Prototyped methods would only work for public properties, if you would keep track of x, y, z as "private" variables the prototype would not work.
I would use the latter, because you might want methods that only work with private/internal variables, but it all depends on context.
function Vector3D(x, y, z) {
// x, y, z is automatically in this scope now, but as private members.
this.magnitude = function() {
return Math.sqrt(x * x + y * y + z *z);
}
}