I was once asked by a student why we write:
parseInt(something)something.toLowerCase()
that is, why one has the variable as a parameter, while the other is applied to the variable.
I explained that while toLowerCase is a method of string objects, parseInt wasn’t designed that way. OK, so it’s window.parseInt, but that just makes it a method of a different object.
But it struck me as an inconsistency — why are some string or other functions not methods of their corresponding objects?
The question is why? Is there a technical reason why parseInt and other functions are not methods, or is that just a historical quirk?
parseIntis a "global" and is actuallywindow.parseInt- does that helptoStringalso does type conversion, yet it’s nottoString(something).atobandbtoaalso turn strings into strings, yet they aren’t used assomething.atob()orsomething.btoa().JSON.parse(str), notstr.parseAsJSON(). Same forbtoa,encodeURI, ....