让人抓狂匪夷所思的4组代码

来源:互联网 发布:雪梨的淘宝店 编辑:程序博客网 时间:2024/04/28 01:23

http://developer.51cto.com/art/201209/355188.htm

下面有4组代码看似简单,但是却另人非常抓狂的,让人匪夷所思。喜欢研究探索的你快来看看吧……

AD:


    1.确保这个值等于ture

    1. if (someBoolean == true) {
    2. doSomething();
    3. }

    2.只有等于ture时我才return ture

    1. if (result == true)
    2. return true;
    3. else
    4. return result;

    3.我就是不信任if

    1. if (result <= 10) {
    2. handling();
    3. }
    4. else if (result > 10) {
    5. otherHandling();
    6. }
    7. else {
    8. handling(); // to be sure
    9. }

    4.要写出一看就懂的代码

    1. function DocumentDotWrite(s){
    2. document.write(s);
    3. }

    原文链接:http://www.aqee.net/horrible-code/