teazean / learnings

记录平时的一些技术问题、解决方案
2 stars 0 forks source link

javascript string escape #197

Open teazean opened 6 years ago

teazean commented 6 years ago

js string 里面有三种编码序列:

  1. hex escape: \xHH, \x 后面固定跟两位16进制的字符
  2. unicode escape: \uHHHH, \u 固定跟四位16进制的字符
  3. unicode escape: \u{HHH*}, \u 后面固定格式 {}, 大括号中不限制位数,该种就是为了弥补 \uHHHH 固定四位的不足

见: http://exploringjs.com/es6/ch_unicode.html#sec_escape-sequences

teazean commented 6 years ago

这三种 string sequence escape 在 string, template, identifier, regex 里面的支持情况:

image

见:http://exploringjs.com/es6/ch_unicode.html#_where-can-escape-sequences-be-used

teazean commented 6 years ago

关于 unicode, 说一点:unicode 规范中,其实有 17(0-16) 个plane:

  1. plane0: 我们常用的都在 plane0 里面,被称为 Basic Multilingual Plane (BMP)
  2. plane1: smp, 包含很多东西, 包含 emoji
  3. plane1-16: 被戏称为 ataral planes

见:https://en.wikipedia.org/wiki/Plane_(Unicode)

teazean commented 6 years ago

补充一下关于 js 的 escape sequences 还有一种表达方式: \ooo\跟着 3 个八进制:

\000: 这种是八进制转码,常见于utf-8,任何小于256均可以使用他的8进制表示,如

To use the same example, the copyright symbol ('©') has character code 169, which gives 251 in octal notation, so you could write it as \251.

兼容性: