I'm trying to make a simple Vector class in Javascript, but since it doesn't support overloading, I experimented with the 'or operator' and came up with the following add function. It works with most inputs except for 0 since it's treated as false instead of a number by the 'or operator'. Is there something else similar in Javascript that I can use?
class Vector
{
constructor(x,y)
{
this.x = x;
this.y = y;
}
// possible inputs
// - add(Vector)
// - add(Number)
// - add(Number,Number)
add(parameter1,parameter2)
{
this.x += parameter1.x || parameter1;
this.y += parameter1.y || parameter2 || parameter1;
}
...
}