Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Is it possible to refer to this property value to use as another property name in JavaScript?

To refer to this.property, there is a getter:

var foo = {
  a: 5,
  b: 6,
  get c() {
    return this.a + this.b;
  }
}

console.log(foo.c) // 11

however, is it possible to do this during object initialization:

var foo = {
  HIDING: 0,
  get state() {
    return this.HIDING;
  }
  [this.HIDING]: { x: 0, y: 0 },
}

I expect

foo: {
  HIDING: 0,
  state: 0,
  0: { x: 0, y: 0 }
}

Self-references in object literals / initializers this doesn't answer my question because it doesn't talk about using another property value as property name

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can only do it after initialization:

var foo = {HIDING: 0};
foo[foo.HIDING] = {x: 0, y: 0};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!