-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

0

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.