2 ms·
The radix param always seemed silly and unnecessary to me. It's a huge footgun that causes a ton of bugs like this. It should have just been another method, "pa
by ramesh31 3y ago
The radix param always seemed silly and unnecessary to me. It's a huge footgun that causes a ton of bugs like this. It should have just been another method, "parseIntBase" or whatever.
- jdlshore 3y agoThere are a lot of these poor API design decisions in early JavaScript, which we're stuck with due to the need for backwards compatibility. ("Don't break the web.") Modern JavaScript APIs tend to be pretty good. Fortunately, early JavaScript was also very small, so you mostly memorize the footguns (or use a linter) and you're good. This is one of them.
- twelve40 3y agowould a linter help here though? it seems to be a perfectly valid call here, except doing something unintended.
- dragonwriter 3y agoA linter would help, if you have a lint rule that requires a locally defined (regular or arrow) function and not a variable inside of map, filter, etc.
- philsnow 3y agoThe problem here is not with parseInt but with map. Map is such a basic function and should have been defined more simply. By all means, make an extended mapE function that passes all kinds of things like position in the input iterable, a reference to the iterable, a reference to an at-first empty “memo” object that will be discarded at the end of the map call, etc etc.
- ketzu 3y agoSeems like a very normal parameter choice for such a function. Nearly every one of the "big" programming languages uses this in some way. To me it would seem weird to have a parseInt and parseIntBase when one is just parseInt(x) -> parseIntBase(x, 10) C++: https://en.cppreference.com/w/cpp/string/basic_string/stol https://en.cppreference.com/w/cpp/string/basic_string/stol Java: https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int- https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.... C#: https://learn.microsoft.com/en-us/dotnet/api/system.int32.parse?view=net-7.0#system-int32-parse(system-string-system-globalization-numberstyles) https://learn.microsoft.com/en-us/dotnet/api/system.int32.pa... But they don't have implicit null/undefined for unspecified parameters, and afaik the map's in these languages do not provide additoinal parameters.
- deleted 3y ago[deleted]