总是三等分的语言 [英] languages that always had triple equals

查看:64
本文介绍了总是三等分的语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一开始就故意设计了哪些流行的编程语言,它们同时具有===和==(并要求程序员弄清楚要使用哪种编程语言).
如今,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?

推荐答案

由于我的记忆不是很可靠,我不能说我还是记得,但是由于ECMA保留了ECMA-262的所有修订版规范中,当在语言中引入严格等于运算符"时,可能会延迟阅读它们.

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.

ECMA-262第2版,但

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.

但是要特别注意的是,Ruby中的===的含义与JavaScript或PHP(它们相当相似)可能有很大的不同.在Ruby中,通常用于包容",即检查是否存在其他事物(例如set),而在另外两种语言中,则用于严格的相等性检查,这意味着不对类型进行任何类型转换.在操作员的任何一方都可以使用它.

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.

这篇关于总是三等分的语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆