Last active
February 19, 2019 05:45
-
-
Save justjavac/a5aa1c0d0d111cf19e852037f4c483db to your computer and use it in GitHub Desktop.
JavaScript 内部字符串编码使用 UTF-16 https://www.ecma-international.org/ecma-262/9.0/index.html#sec-ecmascript-language-types-string-type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JavaScript 字符串编码使用 UTF-16 | |
"💩".length === 2; | |
"💩" === "\u{1F4A9}"; // es6 | |
"💩" === "\uD83D\uDCA9"; // es5 | |
// 同一个编码可能使用不同的码位 | |
"ò" === "ò"; // ❎ | |
"ò" === "\xF2"; // ✅ | |
"ò" === "o\u0300"; // ✅ | |
"o\u0300".normalize("NFC") === "\xF2"; // ✅ es6 提供了 normalize 函数 | |
"👨👩👧👦".length === 11; | |
"👨👩👧👦" === "\u{1F468}\u200D\u{1F469}\u200D\u{1F467}\u200D\u{1F466}"; | |
"👨" === "\u{1F468}"; | |
"👩" === "\u{1F469}"; | |
"👧" === "\u{1F467}"; | |
"👦" === "\u{1F466}"; | |
[..."👨👩👧👦"]; // [ "👨", "", "👩", "", "👧", "", "👦" ] | |
// 在 Unicode 支持不完善的系统上按退格键,能看到这些家庭成员一个接一个的消失。 | |
// 一家人就是要齐齐整整 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
提交评论时遇到了这个