I don't get why JavaScript wasn't changed years ago to not do all this overloading. The RegExp() function should only accept strings... Why would someone want to input something other than a string into the RegExp() function? If you want to do regular expressions on strings that reside inside some other data type (e.g. array), then make a new function that makes use RegExp() and give this new function a proper name to reflect what it does...
When is this overloading shit helpful? There's no way the pros benefit the cons. It just creates problems and solves nothing.
The actual issue is that there is NOT an overload that takes an object. The object is coerced into a string BECAUSE the method can't handle accepting objects.
If {} is turned into "[object Object]", then that is overloading of what {} means. The RegExp() function should simply reject the input of {} and return an error stating that it can only take strings.
View all comments
1
u/OnceMoreAndAgain Mar 20 '24 edited Mar 20 '24
I don't get why JavaScript wasn't changed years ago to not do all this overloading. The RegExp() function should only accept strings... Why would someone want to input something other than a string into the RegExp() function? If you want to do regular expressions on strings that reside inside some other data type (e.g. array), then make a new function that makes use RegExp() and give this new function a proper name to reflect what it does...
When is this overloading shit helpful? There's no way the pros benefit the cons. It just creates problems and solves nothing.