Answer the question
In order to leave comments, you need to log in
What's the best way to chain if-elseif-else calls with elseif-else hidden by default?
So it seems to work, only by default you need to hide the elseif, else methods. how can it be done better?
class BaseLol {
#isNextIf = false;
public if(condition: boolean) {
if (condition) {
this.#isNextIf = false;
} else {
this.#isNextIf = true;
}
return this as Omit<this, "if">;
}
public elseif(condition: boolean) {
if (this.#isNextIf && condition) {
this.#isNextIf = false;
}
return this;
}
public else() {
if (this.#isNextIf) {
this.#isNextIf = false;
}
return this as Omit<this, "else" | "elseif">;
}
}
Answer the question
In order to leave comments, you need to log in
if (condition) {
this.#isNextIf = false;
} else {
this.#isNextIf = true;
}
// this.#isNextIf = !condition;
if (this.#isNextIf && condition) {
this.#isNextIf = false;
}
// this.#isNextIf &= !condition;
if (this.#isNextIf) {
this.#isNextIf = false;
}
// this.#isNextIf = false;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question