Self referencing a key in the object assignment

Viewed 71

So I have had a quick look online and not found anyone suggesting what I have seen in the codebase I am working on and would like to know if what I am seeing is a good idea or does it have some possible side effects I don't know about.

The example below is common to what I see using the const NOT this. its more or less static (no real setters/getters).

const CSS = {
  something: '.something',
  getSomethingByAnother: another => `${CSS.something}*=${another}`,
};

module.exports = CSS;

The more suggested solution would be to use this not the const

const CSS = {
  something: '.something',
  getSomethingByAnother: function(another) {return `${this.something}*=${another}`;},
};

module.exports = CSS;
0 Answers
Related