What is the point of unicode escape sequences in identifier names in JavaScript?
JavaScript allows for having unicode escape sequences in identifier names... for example:
var \u0160imeVidas = "blah";
The above variable starts with the (croatian) letter Š, so that the complete name of the variable is "ŠimeVidas". Now, this is neat, but what's the point? Is 开发者_如何学Gothere any scenario where this feature may be of any use?
Let’s say you’ve got a library stored in UTF-8 and that the author choose to use non-ASCII characters in the APIs. Then, let’s say that—for some reason—you need to access this library from a file stored in ASCII. Allowing the Unicode escape sequences in identifiers allows you to do that. There could be other such scenarios, but that’s one example.
The only use I can think of for using the unicode escape sequence when declaring variables is for obfuscation. You can, of course, type the following for the same variable:
var ŠimeVidas = "blah";
Now, if you were to refer to this variable with a random character in the string replaced with the unicode escape sequence, it would be much more difficult to search for and find those references. Of course, like most other obfuscation technique it would be easily reversible.
If you wanted to use a unicode character that isn't mapped to an Alt+Num combination, it could save time on searching for the key code in charmap (or your OS' equivalent). Not great for saving bytes, though.
精彩评论