在update中调用addBalls函数时,if使用嵌套的方式会使性能更好吗?

来源:5-1 性能优化

qq_感谢永远有歌把心境道破_03171663

2016-12-07 00:19

像这样

if(curSeconds!==nextSeconds){

addBalls(MARGIN_LEFT+46.5*square, MARGIN_TOP, nextSeconds%10);

if(parseInt(curSeconds/10)!==parseInt(nextSeconds/10)){

addBalls(MARGIN_LEFT+39*square, MARGIN_TOP, parseInt(nextSeconds/10));

if(curMinutes%10!==nextMinutes%10){

addBalls(MARGIN_LEFT+27*square, MARGIN_TOP, curMinutes%10);

if(parseInt(curMinutes/10)!==parseInt(nextMinutes/10)){

addBalls(MARGIN_LEFT+19.5*square, MARGIN_TOP, parseInt(curMinutes/10));

if(curHours%10!==nextHours%10){

addBalls(MARGIN_LEFT+7.5*square, MARGIN_TOP, curHours%10);

if(parseInt(curHours/10)!==parseInt(nextHours/10)){

addBalls(MARGIN_LEFT, MARGIN_TOP, parseInt(curHours/10));

}

}

}

}

}

curTimeSeconds=nextTimeSeconds;

}


写回答 关注

1回答

  • qq_感谢永远有歌把心境道破_03171663
    2016-12-07 00:20:05
    if(curSeconds!==nextSeconds){
    		addBalls(MARGIN_LEFT+46.5*square, MARGIN_TOP, nextSeconds%10);
    		if(parseInt(curSeconds/10)!==parseInt(nextSeconds/10)){
    			addBalls(MARGIN_LEFT+39*square, MARGIN_TOP, parseInt(nextSeconds/10));
    			if(curMinutes%10!==nextMinutes%10){
    				addBalls(MARGIN_LEFT+27*square, MARGIN_TOP, curMinutes%10);
    				if(parseInt(curMinutes/10)!==parseInt(nextMinutes/10)){
    					addBalls(MARGIN_LEFT+19.5*square, MARGIN_TOP, parseInt(curMinutes/10));
    					if(curHours%10!==nextHours%10){
    						addBalls(MARGIN_LEFT+7.5*square, MARGIN_TOP, curHours%10);
    						if(parseInt(curHours/10)!==parseInt(nextHours/10)){
    							addBalls(MARGIN_LEFT, MARGIN_TOP, parseInt(curHours/10));
    						}
    					}
    				}
    			}
    		}
    		curTimeSeconds=nextTimeSeconds;
    	}


炫丽的倒计时效果Canvas绘图与动画基础

学习HTML5中最激动人心的技术Canvas,彻底释放自己的创造力

96776 学习 · 1000 问题

查看课程

相似问题