Skip to content

Commit c850187

Browse files
committed
Merge branch 'gh-pages' of github.com:ruanyf/es6tutorial into gh-pages
2 parents 791fa92 + 7b7d2a9 commit c850187

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)