TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Valid JavaScript variable names

91 点作者 mathias超过 13 年前

14 条评论

bwarp超过 13 年前
Whilst this is a good novelty, please please please don't do this - ever!<p>As my father said "just because you can put your penis in a goat, doesn't mean you should".
评论 #3617118 未加载
评论 #3617178 未加载
rhplus超过 13 年前
<i>An Identifier is an IdentifierName that is not a ReservedWord.</i><p>In .NET CLR languages, you can use Unicode for identifiers like in JS, but an interesting side-effect of the 'common' aspect of the CLR is that you can use reserved keywords too. This is because reserved words in one language are not necessarily reserved words in another language.<p>Someone could write the following valid definition in VB.NET:<p><pre><code> Public Property ushort() AS Integer </code></pre> And because it's a reserved keyword in C# you'd have to reference it using the '@' escape:<p><pre><code> foo.@ushort = 123; </code></pre> (There are probably far more confusing examples than this)
meow超过 13 年前
For any one curious, 'ಠ' is pronounced as 'Ta' (Kannada language) :)
评论 #3617028 未加载
评论 #3617208 未加载
kragen超过 13 年前
The most legitimate use for this is for top-level namespaces, which need to be short or they'll junk up your code like crazy. jQuery already took $, and Underscore took _. Maybe 木, ϗ, _⃗, 个, î, 人, Ǝ (not ∃, that's illegal!), ℵ, 二, ℜ, 龍, ℕ, 八, Δ, 大, ʃ, ː, 卐, or as mentioned below, λ? ˀ is probably too obnoxious though.<p>For no particularly good reason, ☺ and ☠ are illegal. I think the Plan9 strategy of considering non-ASCII characters as identifier characters by default is probably a better one than changing the language grammar every time the Unicode standard revs.<p>(As mentioned in another comment, <a href="http://canonical.org/~kragen/setting-up-keyboard.html" rel="nofollow">http://canonical.org/~kragen/setting-up-keyboard.html</a> <a href="https://github.com/kragen/xcompose" rel="nofollow">https://github.com/kragen/xcompose</a>. The Chinese I copied and pasted from <a href="http://www.mdbg.net/chindict/chindict.php?page=radicals" rel="nofollow">http://www.mdbg.net/chindict/chindict.php?page=radicals</a> though.)
adavies42超过 13 年前
&#62; Browsers support identifiers that unescape to a reserved word, so long as at least one character is escaped using a Unicode escape sequence.<p>i smell new xss exploits....
jacobr超过 13 年前
So who creates the λ functional JavaScript library?
评论 #3620596 未加载
enko超过 13 年前
It's a valid ruby method name!<p><pre><code> def ಠ_ಠ puts 'i like turtles' end</code></pre>
评论 #3617183 未加载
评论 #3617325 未加载
Zarathust超过 13 年前
The tutorial about "How to write unmaintanable code" would love this. They already have some hints about putting accents on "int i" and other subtileties like that<p><a href="http://thc.org/root/phun/unmaintain.html" rel="nofollow">http://thc.org/root/phun/unmaintain.html</a>
rogerbinns超过 13 年前
For those who like SQLite, it allows you to create tables and columns with zero length names (you have to quote) and it does indeed work correctly when you use them. This is valid:<p>CREATE TABLE ""("" "");<p>A zero length table name with one column with a zero length name having a type of a zero length name.
rll超过 13 年前
Works fine in PHP as well:<p><pre><code> php &#62; $ಠ_ಠ = 1; php &#62; echo $ಠ_ಠ; 1 php &#62; $π = pi(); php &#62; echo $π; 3.1415926535897931159979634685442 php &#62; function ಠ_ಠ() { echo 1; } php &#62; ಠ_ಠ(); 1</code></pre>
noblethrasher超过 13 年前
Works in C# as well...
moe超过 13 年前
Yup, it does indeed work. <a href="http://jsfiddle.net/bJAed/" rel="nofollow">http://jsfiddle.net/bJAed/</a>
r4vik超过 13 年前
why shouldn't it be?
bobowzki超过 13 年前
Because it's awesome!