I want to create an object in which the class uses the data of two other classes of the same object.
const MatchReplace = {
Username: {
RegExp: new RegExp('%USERNAME%', 'g'), // Joined user name
Value: 'DareFox'
},
UserWithTag: {
RegExp: new RegExp('%USERWITHTAG%', 'g'), // User#XXXX
Value: 'DareFox#0100'
},
ServerName: {
RegExp: new RegExp('%SERVERNAME%', 'g'), // Name of this server
Value: 'StackOverflow'
},
MemberCount: {
RegExp: new RegExp('%MEMBERCOUNT%', 'g'), // Member count (human & bots)
Value: '1005'
},
HumanCount: {
RegExp: new RegExp('%HUMANCOUNT%', 'g'), // Only human count
Value: '1000'
},
BotCount: {
RegExp: new RegExp('%BOTCOUNT%', 'g'), // Only bot count
Value: MatchReplace.MemberCount.Value - MatchReplace.HumanCount.Value // Expected: 5
}
}
But I get an error:
Value: MatchReplace.MemberCount.Value - MatchReplace.HumanCount.Value
^
ReferenceError: Cannot access 'MatchReplace' before initialization
Why does this not work and how to make it work?