0

How do we achieve this reference to the same object, if at all possible?

player = {
    "atk": 24,
    "hp": 343,
    "spd": 104,
    "tick": (player.spd * 0.12).toFixed(2),
}

I tried with this but doesnt work. Or just I used wrong way.

written on Javascript or jQuery

KJELYAZKOV
  • 13
  • 4
  • 1
    See the [linked question's answers](https://stackoverflow.com/questions/4616202/self-references-in-object-literal-declarations) for details. In your particular case, you probably want an accessor property: `get "tick"() { return (this.spd * 0.12).toFixed(2); }` – T.J. Crowder Aug 20 '20 at 11:32
  • 1
    Side note: None of your property names needs to be in double quotes. They *can* be, but they don't have to be. Only property names that aren't valid identifier names have to be in quotes, like `"something with a space"`. – T.J. Crowder Aug 20 '20 at 11:33
  • 1
    thanks, man! It works. I appreciate the side note! @T.J.Crowder – KJELYAZKOV Aug 20 '20 at 11:35

0 Answers0