0

I want do declare a variable inside an object using a function that is being declared in that same object. But when I try I get an error:

const obj = {
  alpha: 4,
  
  somestuff: function()
  {
    return 120;
  },
  
  // Does not work
  beta: this.somestuff()
  // Does not work
};

// Works
obj.beta = obj.somestuff();
console.log(obj.beta);
// Works

How can I make it work when object is being declared, not after it was declared

Ruslan Plastun
  • 1,985
  • 3
  • 21
  • 48
  • 1
    That's not a *perfect* fit, but it should contain how to do it (ignoring the first answer since I don't think getters are appropriate here). – Carcigenicate Oct 13 '18 at 12:32
  • Well, it looks now that it's better to simply do this after the **obj** is declared, but still thanks)) – Ruslan Plastun Oct 13 '18 at 12:38

0 Answers0