欢迎您来到“名字什么都是浮云”的博客空间!

代码优化与规范

没有优化的代码

 

function findShape(flags, point, attribute, list) {

    if(!findShapePoints(flags, point, attribute)) {

        if(!doFindShapePoints(flags, point, attribute)) {

            if(!findInShape(flags, point, attribute)) {

                if(!findFromGuide(flags,point) {

                    if(list.count() > 0 && flags == 1) {

                          doSomething();

                    }

                }

            }

       }

    }   

  }

 

优化后的代码

 

function findShape(flags, point, attribute, list) {
    if(findShapePoints(flags, point, attribute)) {
        return;
    }

    if(doFindShapePoints(flags, point, attribute)) {
        return;
    }

    if(findInShape(flags, point, attribute)) { 
        return;
    }

    if(findFromGuide(flags,point) {
        return;
    }

    if (!(list.count() > 0 && flags == 1)) {
        return;
    }

    doSomething();
 }

  

 

posted @ 2017-01-10 21:16  名字什么都是浮云  阅读(164)  评论(0)    收藏  举报