[英]How to shorten this if statement?
我有一個if statement
像這樣:
if(this.exercisesDoneArray[ind][i].done && this.exercisesDoneArray[ind][1].done
&& this.exercisesDoneArray[ind][i].exercise === this.slides.clickedSlide.nextElementSibling.nextElementSibling.id
|| this.exercisesDoneArray[ind][1].exercise === this.slides.clickedSlide.nextElementSibling.nextElementSibling.id){
但我想知道如何縮短此時間。
如何使用一些變量?
var ex1 = this.exercisesDoneArray[ind][i],
ex2 = this.exercisesDoneArray[ind][1],
nextSlide = this.slides.clickedSlide.nextElementSibling.nextElementSibling.id;
if(ex1.done && ex2.done && ex1.exercise === nextSlide || ex2.exercise === nextSlide){
使用幾個變量,然后在全局變量之外放置其他變量(如果您在其中檢查您的主要鍛煉是否已完成),因為必須始終這樣做,因此如果使用and和,則不必總是在另一個變量中進行內部檢查
var currentExcercise = this.exercisesDoneArray[ind][i];
var baseExcercise = this.exercisesDoneArray[ind][1];
var slideId = this.slides.clickedSlide.nextElementSibling.nextElementSibling.id;
if (!baseExcercise.done) {
return false;
}
if(currentExcercise.done && currentExcercise.exercise === slideId || baseExcercise .exercise === slideId ){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.