1

I have a property declared below:

export const properties = {
  username: 'admin',
  password: 'pass',
  environment: 'test1',
  // Trying to construct the url so it becomes http://test1.com
  url: 'http://'  + environment + '.com',

};

I would like to reuse environment inside the url value. However it can't seem the find it. I have tried the following and had no luck:

url: 'http://'  + environment + '.com',
url: 'http://'  + this.environment + '.com',
url: 'http://'  + properties.environment + '.com',

Does anyone have any idea on how it can be done? Thank you

user3054735
  • 117
  • 1
  • 2
  • 8

1 Answers1

1

You can try one of the following:

const properties = {
  username: 'admin',
  password: 'pass',
  environment: 'test1',
  // Trying to construct the url so it becomes http://test1.com
  get url() {
    return 'http://' + this.environment + '.com';
  },
};

(The above makes use of getter function, which has a different behaviors than a normal property, but it behaves very similarly in most cases)

or

const environment = 'test1';

const properties = {
  username: 'admin',
  password: 'pass',
  environment,
  // Trying to construct the url so it becomes http://test1.com
  url: 'http://'  + environment + '.com',
};
AngYC
  • 3,051
  • 6
  • 20