Skip to content

Commit 7b7d2a9

Browse files
authored
Merge pull request ruanyf#461 from outloudvi/gh-pages
Fix minor typo of "string.md"
2 parents 2fe1490 + acb05c6 commit 7b7d2a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ s.charCodeAt(0) // 55362
6565
s.charCodeAt(1) // 57271
6666
```
6767

68-
上面代码中,汉字“𠮷”(注意,这个字不是”吉祥“的”吉“)的码点是`0x20BB7`,UTF-16编码为`0xD842 0xDFB7`(十进制为`55362 57271`),需要`4`个字节储存。对于这种`4`个字节的字符,JavaScript不能正确处理,字符串长度会误判为`2`,而且`charAt`方法无法读取整个字符,`charCodeAt`方法只能分别返回前两个字节和后两个字节的值。
68+
上面代码中,汉字“𠮷”(注意,这个字不是“吉祥”的“吉”)的码点是`0x20BB7`,UTF-16编码为`0xD842 0xDFB7`(十进制为`55362 57271`),需要`4`个字节储存。对于这种`4`个字节的字符,JavaScript不能正确处理,字符串长度会误判为`2`,而且`charAt`方法无法读取整个字符,`charCodeAt`方法只能分别返回前两个字节和后两个字节的值。
6969

7070
ES6提供了`codePointAt`方法,能够正确处理4个字节储存的字符,返回一个字符的码点。
7171

0 commit comments

Comments
 (0)