I'm trying to do something I don't remember/find if it is possible in javascript.
I have an object constructor "Point" and I want to know if it possible to, for example, sum two different objects like bellow.
function Point(x, y) {
this.x = x;
this.y = y;
}
a = new Point(1,2);
b = new Point(2,3);
c = a+b;
console.log('a: ', a)
console.log('b: ', b)
console.log('c: ', c)
a = Point {x: 1, y: 2}
b = Point {x: 2, y: 3}
Expected result: c = Point {x: 3, y: 5}
a.add(b), within which you do the summing with the appropriate behaviour for that type of object.Point.add(obj1, obj2)rather thanobj1.add(obj2). The first way just looks cleaner.a.add(...), you can subclassawith some other geometric shape for which adding a point would also make sense. WithPoint.add(...)you hardcode the behaviour to only points.