-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

4

1 回答 1

0

不可能。将包含不同键/值对(即选项)的对象传递给构造函数。方法重载不可用。

于 2016-06-04T20:35:35.757 回答