I have this method called 'leer' (Learn in English) that atm takes in 2 words. 1 for a category and 1 to put in that category. Now I would like to add functionality whereby I can add a bunch of words to one category.
WoordenSchat.prototype.leer = function(categorie,naam){
if (!this.hasOwnProperty(categorie)){
this[categorie] = []
this[categorie].push(naam)
}
else {
this[categorie].push(naam)
}
}
I could solve this by figuring out what sort of variable I receive in 'naam' via typeOf and then act accordingly, but I feel like this would result in a messy piece of code.
What I would like to do is have 2 functions:
- leer (categorie,naam)
- leer (categorie, [naam])
where by the one with an array of names (naam (Dutch) in plural) would call the first one in a for loop.
Is this possible in JavaScript? Because as far as I know there is no way of telling a Javascript method: "You take in this type of variable and this type only"
I know in python you could do things like this def functionName (categorie:str, naam: str) etc.