Greetings All!
I’m working on a simple todo app. (from the Odin Project)
I’ve run into a problem working with class objects in js.
Deciding to utilize the class object to store the data I need for the various page elements I have a few object properties that look like this:
this.priorityElement = {
'element': 'p',
'attributes': {
'data-id': this.id,
'class': 'priority',
'text': this.priority
}
}
The reason for this is because I set up the class like this:
class Task{
constructor(name, id){
this.project = null
this.id = id
this.name = name
this.complete = false
this.priority = null
this.description = null
this.dueDate = null
this.checkList = null
}
The problem I’m having is when I run a createNewTask function, and set one of the null values (let’s say priority) in the function.
the value is set, but the corresponding value ( the one inside priortyElement “‘text’: this.priority”) isn’t updating.
I think I can solve the problem like this:
example:
class Task{
constructor(project=null, name, id, complete=false, priorty=null, description=null, dueDate=null, checkList=null){
this.project = project
this.id = id
this.name = name
this.complete = false
this.priority = priority
this.description = description
this.dueDate = dueDate
this.checkList = checkList
But that just looks clunky, and I’m trying hard to keep everything clean.
My question is:
A) Is the way I’m trying to set the class up dumb?
B) Is there a way to update the value the way I’m trying for?
C) If A and B are a negative, is there a cleaner way to set up the parameters of the constructor for the class?
example:
class Task{
constructor(
name,
id,
project=null,
complete=false,
priority=null,
description=null,
dueDate=null,
checkList=null
)
D) And if not A, B, or C, am I just completely daft and need to find a different way to do this?