toLowerCase()如何在Javascript中工作? [英] How does toLowerCase() work in Javascript?

查看:52
本文介绍了toLowerCase()如何在Javascript中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用该函数会使整个字符串全部变为小写.但是,我对幕后工作感到好奇.我在任何地方都找不到有关其工作原理的解释.它是否基本上遍历字符串中的每个索引并检查字符是什么以及是否存在小写字符?

I understand that using that function will make an entire string all lowercase. However, I'm curious in the behind the scenes work. I can't find an explanation anywhere on how it works. Does it basically loop through every index in the string and check to see what the character is and if there is a lower case character available?

推荐答案

通常,查找此类信息的最佳位置是

In general the best place to look for such information is the ECMAScript specification:

采取以下步骤:

  1. 通过this值作为参数调用CheckObjectCoercible.
  2. 让S成为调用ToString的结果,并为其指定此值.
  3. 让L为一个字符串,其中L的每个字符或者是S对应字符的Unicode小写等效项,或者如果不存在Unicode小写等效项,则为S的实际对应字符.
  4. 返回L.

出于此操作的目的,字符串的16位代码单元在Unicode Basic Multilingual Plane中被视为代码点.代理代码点直接从S传输到L,而无需任何映射.

For the purposes of this operation, the 16-bit code units of the Strings are treated as code points in the Unicode Basic Multilingual Plane. Surrogate code points are directly transferred from S to L without any mapping.

必须根据Unicode字符数据库中的大小写映射得出结果(这不仅包括UnicodeData.txt文件,而且还包括Unicode 2.1.8及更高版本中随附的SpecialCasings.txt文件)./p>

The result must be derived according to the case mappings in the Unicode character database (this explicitly includes not only the UnicodeData.txt file, but also the SpecialCasings.txt file that accompanies it in Unicode 2.1.8 and later).

第3步是您真正感兴趣的部分.如您所见,"L"的细节产生取决于执行情况.如果您有兴趣进一步深入研究,那么下一个地方应该是 V8引擎本身.

Step 3 is the part you're really interested in. As you can see, the details of how "L" is produced are up to the implementation. If you're interested in going deeper the next place to look would be e.g. the V8 engine itself.

这篇关于toLowerCase()如何在Javascript中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆