Entries

笔记:JavaScript中的逻辑异或 / Note: Logical XOR in JavaScript

JavaScript中没有异或运算符,所以碰到要用异或运算的时候就头疼了。
We all know there is no Logical XOR operator in JavaScript, so we got pain when need a XOR operate.

这篇文章中总结了几种异或运算的变通实现,在文章的最后指出“!A != !B”这样一种简单但有效的办法……
In the artical shown above it listed some usual way to simulate XOR operate, and at the end it showed a clear (and beautiful) way to do this: "!A != !B".

!运算符的结果只会是布尔值……为什么这个方法我没想到呢TvT
The result of a "!" operate will be surely boolean... So this could avoid problems that variables other than boolean will have more than one possible values equivalent to boolean true.

虽然说写成“Boolean(A) != Boolean(B)”似乎更高效一点,但这样的话看起来实在不够优雅……
Though it seems "Boolean(A) != Boolean(B)" could have the best performance, but it looks really UGLY...
引用此文章(FC2博客用户)
http://shinron4.blog126.fc2blog.us/tb.php/31-60df8eb8

引用

留言

发表留言

发表留言
只对管理员显示

Appendix

自我介绍

优雅的神棍 / Elegant Tales

Author:优雅的神棍 / Elegant Tales
神棍你好,神棍再见。

最新引用

QR

QR

羔羊们啊

加为好友

和此人成爲好友

搜寻栏