logoalt Hacker News

llmslave2last Wednesday at 10:30 AM0 repliesview on HN

You can do it multiple ways. Like in go:

   cloj := func() {
     val := 1
     return func(m string) {
       switch m {
         case "inc": val = val + 1
         case "dec": val = val - 1
       }
     }
   } ()
   
   cloj("inc")

In JS you can close upon state and return an object, which is essentially how classes work in the language.

   let cloj = (() => {
     let x = 0; return { inc: () => x++, dec: () => x-- }
   })()
   cloj.inc()