JavaScript/HTML 是大写还是小写?
在 JS/HTML 中,为了兼容性/JIT 编译性能,使用大写还是小写更好? 例如:
<DIV> my content </DIV>
<div> my content </div>
ALERT(DOCUMENT.LOCATION);
alert(document.location);
这不是一个新手问题,我知道小写是事实上的标准。 但由于我见过一些大写的JS+HTML,我想知道哪个会更好写。(比如SQL是完全大写的?)
Is it better for sake of compatibility/JIT-Compiling performance to use UPPER CASE or lower case, in JS/HTML? For eg:
<DIV> my content </DIV>
<div> my content </div>
ALERT(DOCUMENT.LOCATION);
alert(document.location);
This is not a newbie question, I know lowercase is the de-facto standard. But since I've seen some uppercase JS+HTML, I was wondering which would be better to write in. (like SQL is fully uppercase?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我不认为这会对速度产生影响。
XHTML:小写标签是 W3C 指定的。
JavaScript:它可能行不通,因为我从未见过任何人的代码在 JS 中使用全部大写。
SQL 完全大写,以区分操作、函数等与实际数据。 您可以使用小写字母,但它的可读性较差(对某些人来说,包括我)。
IMO,费力地浏览一堆大写标签比小写标签可读性差。 我想说用户代理并不关心标签的大小写。 这里有一些历史:当我在 1999 年制作一个网站时,大写标签是标准。
您仍然可以找到一些狡猾的未更新的网站,它们仍然写着
I don't think it'd make a difference, speed-wise.
XHTML: Lowercase tags is what the W3C specified.
JavaScript: It probably wouldn't work, because I have never seen anyone's code use all caps in JS.
SQL is fully uppercase to differentiate the actions, functions, etc from the actual data. You can use lowercase, but it becomes less readable (to some, me included).
IMO, wading through a heap of uppercase tags is less readable than lowercase tags. I'd say user agents don't care what case the tags are. Here's a little bit of history: when I made a website in 1999, uppercase tags were the standard.
You can still find some dodgy non updated websites out there that still write
使用
是不正确的(至少在 xhtml 中); 它是一个
。
同样,我会在 javascript 中使用小写字母(对于
alert(document.location);
),因为这是他们的名字 ;-pIt is incorrect (in xhtml, at least) to use
<DIV>...</DIV>
; it is a<div>...</div>
.Likewise, I'd use lower-case in the javascript (for
alert(document.location);
), as that is their names ;-p我无法想象它会对兼容性或性能产生任何影响。 我认为有些人发现大写字母更容易识别为标记或代码而不是内容。
如果需要的话,您可以做一些基准测试。
(XHTML 指定小写字母作为标准,因此如果您的目标是满足验证器的要求,那么就这样做)
I can't imagine it making any difference compatibility- or performance-wise. I think some people find UPPERCASE easier to recognize as markup or code rather than content.
You can do some benchmarks, if you must.
(XHTML specifies lowercase as the standard, so if your goal is satisfying validators, then go with that)
JavaScript(使用 Fx3.0)区分大小写。
HTML 允许混合大小写的标签,XHTML 只要求小写的标签、属性。
JavaScript is (using Fx3.0) case sensitive.
HTML allows mixed-case tags, XHTML demands lower-case only tags, attributes.
它确实与 javascript 有所不同,因为它区分大小写。
公认的 html 社区标准是小写,尽管浏览器并不关心。
所以善待那些稍后必须阅读你的代码的人!
It certainly makes a difference with javascript since it is case sensitive.
The accepted community standard for html is lowercase, even though browser don't care.
So be nice to the ones who have to read your code later!
我肯定会尽可能使用小写。 我倾向于喜欢驼峰式大小写多字变量名称,但即使这样也可以避免使用下划线。
I'd definitely go with lowercase wherever possible. I tend to like camel casing multi-word variable names, but even that can be eschewed in favor of underscores.