JSFiddle - React, Tailwind, and code Playground
by fairmutex
JavaScript
var Vector = function(x,y){
this.x = Number(x);
this.y = Number(y);
};
Vector.prototype.plus = function(vect){
return new Vector(this.x+vect.x,this.y+vect.y);
};
Vector.prototype.minus = function(vect){
return new Vector(this.x-vect.x,this.y-vect.y);
};
Object.defineProperty(Vector.prototype,'length',{
get: function(){
return Math.sqrt(Math.pow(this.x,2) + Math.pow(this.y,2));
}
});