Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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 支持不完善的系统上按退格键,能看到这些家庭成员一个接一个的消失。
// 一家人就是要齐齐整整
@justjavac

This comment has been minimized.

Copy link
Owner Author

justjavac commented Jan 30, 2019

提交评论时遇到了这个

@zxmLoveLife

This comment has been minimized.

Copy link

zxmLoveLife commented Jan 30, 2019

Webkit默认JS引擎JavaScriptCore里String的iterator实现,和Safari的执行结果一致。
image

Chrome下执行结果:
image
估计是length是11,不足的位数默认填充了undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.