Help us understand the problem. What is going on with this article?

JavaScriptの文字列を全部小文字/大文字化する

More than 5 years have passed since last update.
var lower = 'ABCabc'.toLowerCase();
var upper = 'ABCabc'.toUpperCase();

ただし、String#toLowerCase と String#toUpperCase はブラウザーのロケーション設定がトルコだと正しい結果を返さないので、代替処理を行う必要がある。

function manualLowercase(s) {
  return s.replace(/[A-Z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) | 32);});
};
function manualUppercase(s) {
  return s.replace(/[a-z]/g, function(ch) {return String.fromCharCode(ch.charCodeAt(0) & ~32);});
};

var lower = manualLowercase('ABCabc');
var upper = manualUppercase('ABCabc');

代替処理を行うかどうかの判定は下記のコードで行う。

if ('i' !== 'I'.toLowerCase()) {
  // 代替処理を行う
} else {
  // toLowerCase(), toUpperCase()を使う
}

じゃあ面倒くさいから全部代替処理をすればいいのか?というとそうでもなくて、
代替処理の方が動作が遅いので可能な限りは通常のtoLowerCase(), toUpperCase()を使うべきなのです。

…というのをAngularJSのコードを読んでて見つけました。こんなの日本に住んでたら絶対わかんないよなー。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした