Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript string escape #197

Open
teazean opened this issue Dec 22, 2017 · 3 comments
Open

javascript string escape #197

teazean opened this issue Dec 22, 2017 · 3 comments

Comments

@teazean
Copy link
Owner

teazean commented Dec 22, 2017

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
Copy link
Owner Author

teazean commented Dec 22, 2017

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

image

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

@teazean
Copy link
Owner Author

teazean commented Dec 22, 2017

关于 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
Copy link
Owner Author

teazean commented Jan 2, 2018

补充一下关于 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.

兼容性:

  • String Literals:可以
  • Template literals: 非严格模式可以,严格模式不可以。
  • Regular expresss literals: 不可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant