-1

I'm from C++, and i try to understand JS OOP. But I have to admit it isn't simple ... I want to create a "simple" class.

Like this :

class Being {
   Being(float A, float B) {...}
   Being(string A, string B) {...}
   Being() {...}
   getInfo() { 
      console.log(...)
   }
   [...]
}

I know there is some ways to do it, like this :

class Being {
 Being(A=null,B=null) {
  if (A === null && B === null) {}
  if (typeof A == String && typeof B == String) {}
  if (!isNaN(A) && !isNaN(B)) {}
 }
}

But i want to know if there is a most elegant way to do this. I kown there is also the function 'constructor' keyword, but it seems to doesn't work for multiples overloading.

Thx

Olivier.B
  • 91
  • 2
  • 9

1 Answers1

0

Not possible. Pass an object containing different key/value pairs aka options to the constructor. Method overloading is not available.

Florian Salihovic
  • 3,921
  • 2
  • 19
  • 26