I noticed that in Internet Explorer (but, unfortunately, not in the other browsers I tested), you can use some Unicode variable names. This made my day, and I was absolutely delighted that I could write fun Unicode-laden code like this:
var ктоείναι草泥马 = "You dirty horse.",
happy☺n☺mat☺p☺eia = ":)Yay!",
ಠ_ಠ = "emoticon";
alert(ктоείναι草泥马 + happy☺n☺mat☺p☺eia + ಠ_ಠ);
For some reason, though, ◎ܫ◎
, ♨_♨
and ☺
are not valid variable names.
Why do ಠ_ಠ
and 草泥马
work, but ◎ܫ◎
, ♨_♨
and ☺
don't?
EDIT: Test it out in your browser on JSFiddle. I've tested it in Internet Explorer 9, Chrome, Firefox, and Opera. So far, it seems to only work in Internet Explorer 9. (I don't know about Internet Explorer 8 and below.) Let me know if it works in another browser.
EcmaScript 262第7.6节说,名称必须以$,_或Unicode字母开头,之后可能包含这些字符,Unicode组合标记,Unicode数字或Unicode连接器标点符号(以及一些格式控制字符,是特定于语言的。)
因此,在您的情况下,允许的标识符与不允许的标识符之间的区别可能在于前导字符是否被视为“字母”。