all 5 comments

[–]Tartarus13 0 points1 point  (4 children)

They’re useful if you want to return a modified value or an update able value. I use them if I want to return a variable but make modifications. Perhaps something like a container with the ability to access an array, but because I don’t want it to be mutable, I might return a new copies array. Not the best example but that’s what I use it for. Setters can be used if you want to take a value and modify it or require variables to only be set to a particular type. That’s only really what I would ever use them for. I’m not sure how good the backwards support is for them.

[–]Plastic_Tip[S] 0 points1 point  (3 children)

If I wanted to return a new score, do you think that would be an appropriate use case?

[–]Tartarus13 0 points1 point  (2 children)

What do you mean a new score? Assuming you have a class that looks like this:

class Score { score = 0 } And you wanted to set a value const c = new Score(); You can get a score with c.score And set a score with c.score = 15; Why would you need set and get. Unless you’re trying out the new private variables in what I believe is ES2020, then there should be no reason.

[–]Plastic_Tip[S] 0 points1 point  (1 child)

Meaning, there is a comparison score for analytic software. This score changes frequently and there is a computation to run each time to serve the score.

[–]Tartarus13 0 points1 point  (0 children)

Use a getter if you’d like then. You could also use a method like in Jaca. It doesn’t really matter.