Ask HN: What are good patterns for holding state?
Here is an example of how I would go about it without classes :
function makePlayer() {
const data = {
x: 100,
y: 100,
health: 300,
speed: 200
}
const methods = {
setHealth(value){
data.health = value
},
// etc...
}
return {...data, ...methods}
}Do you think this is a good approach? If not, why?
EDIT: The question is meant to be general and not specific to a given framework or library. For something like React you use what is given by the library. There isn't much room for choice here.