The issue is you're using Math.sum(x,y)
as a static function instead of an Object reference.
You can change your function to:
static sum(a, b){
return a + b;
}
Object references call for you to pass variables to the constructor or dynamically assign them through a function.
let x, y;
class Math {
//The constructor has optional parameters which default to 0.
constructor(first=0, second=0){
this.x = first;
this.y = second;
}
//Makes a sum with the variables passed through the constructor.
sum(){
return x+y;
}
//sets the x value
changeX(num){ x = num; }
//returns the x value
getX(){ return x; }
//This function saves it to the object beforehand so you may retrieve it later.
sumSaved(first, second){
this.x = first;
this.y = second;
return x + y;
}
//Assigned through the constructor.
let foo = new Math(first:1,second:2);
foo.sum(); //returns 3 because 1+2=3
foo.changeX(2);
foo.sum(); //returns 4 because 2+2=4
//Assigned through a function.
let bar = new Math();
bar.sumSaved(4,6); //returns 10 and overwrites variables.
bar.getX(); //returns 4, because you saved it earlier.
See here for information on static functions.
See here on when you should use static functions.
Also, for information about default exports, read here.