I am refactoring my code now..and I have to refactor my lots of if..else statements, so I am now creating many functions by each conditions.
Code:
class Strategy {
constructor(state) {
this.state = state;
if(this.state === 1){
return first();
}else if (val === 2){
return second();
}else if (val === 3){
return third();
}
}
}
function first(){
//do something
}
function second(){
//do something
}
function third(){
//do something
}
let firstClass = new Strategy(1);
Is it OK to declare all each functions by condition??? Or, Is it better to declare each functions in prototype method?/?
Aucun commentaire:
Enregistrer un commentaire