0
const obj = {
  foot: [1, 3, 5],
  shoe: [7, 9, 11],
  dump: // a function that sets obj.dump as the value of (this.foot[1] + this.shoe[0])
        // (otherwise known as `10`)
}

Things I have tried (IIFE, anon function, etc), referring to obj.dump returns the function used to do the add.

I would like obj.dump to instead return 10

What is the proper syntax for that?


Side note, how would I search for this? What could this pattern be called?

monsto
  • 1,178
  • 1
  • 13
  • 26
  • 3
    Maybe you want an accessor function (aka getter/setter)? it would just be `get dump() { return this.foot[1] + this.shoe[0]; }` – Heretic Monkey Jul 01 '21 at 18:11
  • @HereticMonkey what sorcery is this?! If you make it a response I'll set it as the answer. Thanks! – monsto Jul 01 '21 at 18:17
  • The question has been closed as a duplicate. Kinglish was only able to add their answer due to the fact that they were writing the answer before VLAZ closed it. – Heretic Monkey Jul 01 '21 at 18:23

0 Answers0