In strongly typed languages, like C# or Java, I can distinguish constructor signatures by argument types.
class Cars {
Cars(string x, string y) {};
Cars(string x, int y) {};
}
But without strong typing in JavaScript, I can only do this, which obviously will not work:
class Cars {
Cars(x, y) {};
Cars(x, y) {};
}
Am I limited to only the number of constructor arguments to distinguish them? Is there some way to create JS constructors that have the same number of args, but of different “types”?
How do I make constructors that know that it should be looking for an string y
in the first constructor, but int y
in the second?