I created a Vector3 function on javascript
function Vector(basex,basey,basez) {
if(!(this instanceof Vector))
return new Vector (x,y,z);
this.x=basex;
this.y=basey;
this.z=basez;
}
Vector.prototype.toString=function(){
return '(' + this.x + ', '+ this.y + ', ' + this.z + ')';
}
s= new Vector(1,2,3); //(1,2,3)
however, when I try to reassign s with
s=Vector(3,4,5)
I get ReferenceError at line NaN: x is not defined
If I use
s=new Vector(3,4,5)
It works, but is this the correct way to reassign my variable? I tried to look up the web for some "reassigning my variable" but only fond that a primitive vars can be reassigned
var n=3;
n=5;
But nothing about functions. Any headups?