-1

I have an object as follows:

let utx = module.exports = {
  params: {
      icon1: 'some value',
      icon2: 'some value',
      type1: {
          messages: {
              accept: {
                  status: utx.params.icon1
              }
          }
      }
  }  
};

I'm trying to reference the icon1 value deep inside the same object but it's not working, i get an error utx is undefined.

Anyone know why this is?

lordZ3d
  • 540
  • 6
  • 20
  • 1
    `let utx = {/*...*/}; module.exports = utx;` because "Cannot access 'utx' before initialization". – str Aug 02 '20 at 15:56

1 Answers1

0

Just occurred to me i have to use a fn call

accept: {
    status: function() {
        return utx.params.icon1;
    }
}

Is working as expcted

lordZ3d
  • 540
  • 6
  • 20
  • If you make it a get accessor you don't have to change the syntax where it's used. – jonrsharpe Aug 02 '20 at 15:54
  • Function or accessor works if you always want it to reference the variable, irrespective of its value. If you always want the object, do the assignment after you've created the object. –  Aug 02 '20 at 15:57