Let's say I have a component TaskList
. It has functions such as addTask
, removeTask
, editTask
, as well as functions like openList
and closeList
. Let's say I create an object for each category of functions, for example object tasks
and object ui
, and then I store the functions in their respective objects, like so:
class TaskList {
constructor(){
this.tasks = {
addTask: function(params){
//Code
},
editTask: function(params){
//Code
}
//etc...
}
this.ui = {
closeList: function(){
//Code
}
openList: function(){
//Code
}
//etc...
}
//etc...
}
}
Then you would call each function like so: this.tasks.editTask(...)
Is this a good approach? If no, what are some better alternatives to effectively organizing class functions?
Aucun commentaire:
Enregistrer un commentaire