总是有三等号的语言
哪些流行的编程语言从一开始就有意设计为同时具有 === 和 ==(并要求程序员弄清楚使用哪一个)。
如今,Javascript、PHP、Ruby(可能还有其他语言)都有一个三等号运算符。但是,尚不清楚这是一个故意的设计决定,还是只是偶然发生(也许是因为该语言以双等号开头,但在某些时候,人们发现双等号并没有完全按照人们希望的方式进行) ).
特别是在 javascript 中,有人记得它第一次出现时是否有三重等于吗?
What popular programming languages were intentionally designed from the beginning to have both === and == (and require the programmer to figure out which one to use).
Javascript, PHP, ruby (and probably others) have a triple equals operator today. But, it is not clear if this was a deliberate design decision, or happened only by accident (perhaps because the language started with double equals, but at some point it was discovered that double equals wasn't quite doing what people wanted it to do).
Specifically in javascript, does anyone remember if it had the triple equals when it first came out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于我的记忆不太可靠,所以我不能说我记得或者,但由于 ECMA 善意地保留了 ECMA-262 规范的所有修订版,因此可以在“严格等于运算符”时推迟阅读它们被引入到语言中。
我在 ECMA-262 第 1 版,也不是 ECMA-262第二版,但在ECMA-262第三版我们在第 11.9.4 章(第 56 页)中找到了它。由此得出的自然结论是:不,JavaScript 在刚出现时并没有
===
。由于你提到的其他语言没有(据我所知)在任何标准化机构中得到批准,我想如果有语言规范的话,很难找到该语言规范的旧版本。
但值得注意的是,Ruby 中
===
的含义可能与 JavaScript 或 PHP 中的含义有很大不同(它们非常相似)。在 Ruby 中,它通常用于“包含”,即检查某些东西是否存在于其他东西(例如集合)中,而在其他两种语言中,它用于严格的相等检查,这意味着不执行类型转换在应用操作符之前先将其置于操作符的任一侧。Since my memory isn't very reliable, I can't say that I remember either or, but since ECMA has kindly kept all revisions of the ECMA-262 specification, it's possible to defer from reading them when the "The Strict Equals Operator" was introduced into the language.
I can't find any mention of it in neither ECMA-262 1st Edition, nor ECMA-262 2nd Edition, but in ECMA-262 3rd Edition we find mention of it in chapter 11.9.4 (page 56). The natural conclusion to draw from this is thus: No, JavaScript did not have
===
when it first came out.Since the other languages you mention aren't (as far as I know) ratified in any standardisation body, I guess it's harder to find old revisions of the language's specification, if there is any such thing as a specification for the language at all.
It's important to note, however, that the meaning of
===
in Ruby can be widely different than in JavaScript or PHP (where it is fairly similar). In Ruby, it's usually used for "subsumption", i.e. to check whether something exists within something else (a set, for instance), while in the two other langauges, it's used for strict equality checking, which means no type conversion is performed on either side of the operator before applying it.