JSFiddle - React, Tailwind, and code Playground
by mrcl
JavaScript
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return `(${this.x}, ${this.y})`;
}
add(p2) {
return new Point(this.x+p2.x,this.y+p2.y)
}
}
var pkt = new Point(12,-34);
var pkt2 = new Point(-4,1);
alert(pkt);
alert(pkt.add(pkt2));