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

203
Views
spread in object definition causing undefined properties in "this"

I have an object which I initialize with bunch of properties in node.js, spreading another object in, and at the end defining a getter.

The problem is the the getter uses this and all the properties defined on the object before the spread don't exist on this.
If I move the spread to the end or start of the object initialization, it works fine.

const obj = { a: 1 }
const obj2 = { 
  prop: 'a',
 ...obj,
 prop2: 'b',
 get test() { 
   return this.prop + this.prop2 
  }
}


console.log(obj2.test); // 'undefinedb'

What can possibly be the reason for that?

Thanks

over 4 years ago · Santiago Trujillo
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!