简体   繁体   English

链接双等于==返回false

[英]chaining double equals == returns false

I have 3 textboxes that I am trying to do some validation that all 3 values match. 我有3个文本框,我试图对所有3个值都匹配进行验证。 I have a simple function: 我有一个简单的功能:

    function DoesSubsriberSignatureMatch() {
    return tbNameOfSubscriber.GetText() == tbSubscriberSig1.GetText() == tbSubscriberReEnter.GetText();
}

I stepped through with the debugger, and it seems in Javascript in Chrome at least, "a"=="a" returns true, but "a"=="a"=="a" returns false. 我逐步调试一下,似乎至少在Chrome的Javascript中,“ a” ==“ a”返回true,但是“ a” ==“ a” ==“ a”返回false。

Why? 为什么?

Coming from Python, perhaps? 来自Python,也许? Most languages don't actually have comparison chaining. 大多数语言实际上没有比较链。 Trying it produces nonsense results. 尝试产生无意义的结果。

Because a == a yields true , and true != a . 因为a == a产生true ,而true != a

(Unless a holds the value true ). (除非a保持值为true )。

Take 采取

"a"=="a"=="a"

and break it down. 并分解。 So first 所以首先

"a" == "a"

equals what? 等于什么? true . true Right. 对。 Now substitute true in for that first part 现在用true代替第一部分

true == "a"

which of course is false 当然哪个是假的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM