TodePond / Habitat

my javascript helpers
MIT License
45 stars 5 forks source link

struct reconsider #76

Closed TodePond closed 1 year ago

TodePond commented 1 year ago

I'm tempted to use struct as more of a class, with a constructor and stuff. But this feels like a bad idea. But then also there's no way to combine the use of struct with classes.

And also, it kinda sucks when default values are objects/arrays because it doesn't create a new one each time.

And also I sometimes use struct for default arguments, which I should probably just do with a spread.

Maybe just get rid of it until I can be better behaved.

TodePond commented 1 year ago

Some different options:

const Player = struct ({
  score: 0,
  health: 10,
  name: "",
})

const lu = Player({name: "Lu"})
const Player = (options = {}) => ({
  score: 0,
  health: 10,
  name: "",
  ...options, 
})

const lu = Player({name: "Lu"})
TodePond commented 1 year ago
Screenshot 2022-12-16 at 22 41 35
TodePond commented 1 year ago

just scrap it

TodePond commented 1 year ago

it's gone