Just put a condition that checks if the argument is a string.
Oh, so something like this?
if (typeof input !== 'string') {
throw new TypeError('RegExp input must be a string');
}
That's actually a great idea! If only the language did exactly that for me so I wouldn't have to track down obscure bugs if one of my colleagues or library authors accidentally forgot to do that!
If only the language just checked the strings you wanted it to check without having to call a function....
If only the script could just automatically figure out whether a number was even or odd without me having to write a function to check it..
If only the language automatically grabbed input from the user so we didn't have to bother making forms and processing the inputs.
If only, right?
Essentially what you're doing here is identical to arguing that c is a bad language because you have to indicate what type a variable is when you declare it... It's an unnecessary step for you, because other languages have features built in that automatically determines what the data type is.
Do you think all languages should be interpreted? If not, why not? If not, why would you point to things that a language COULD do automatically and then shit on that language for not doing it automatically?
View all comments
Show parent comment
1
u/SoInsightful Mar 21 '24
Oh, so something like this?
That's actually a great idea! If only the language did exactly that for me so I wouldn't have to track down obscure bugs if one of my colleagues or library authors accidentally forgot to do that!