I’m looking through the code for kibo.js and found this function:
Kibo.capitalize = function(string) {
return string.toLowerCase().replace(/^./, function(match) { return match.toUpperCase(); });
};
Anyone have any ideas why they might use this instead of just .toUpperCase?
PS – Kibo is found at https://github.com/marquete/kibo/blob/master/kibo.js
It basically converts the entire string to lower case first, and then capitalizes just the first letter.
capitalize:…as opposed to
toUpperCase:toLowerCase:Some languages also have a
titleizemethod which capitalizes the first letter of each word, as in a title/proper name:Notice that it doesn’t capitalize “and”, “of”, “the”, etc. unless they are the first word in the string.