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

107
Views
is it possible to apply object deconstruct to Classes in JS?

Is something like this possible in some way for Classes in JS

class Foo {
  constructor(first) {
    this.first = first;
  }
  printFirst() {
    console.log(this.first);
  }
  printSecond(second) {
    console.log(second);
  }
}

const newFoo = new Foo("bar");

newFoo.printFirst();
// returns 'bar'
newFoo.printSecond("baz");
// returns 'baz'

const { printFirst, printSecond } = newFoo;

printSecond("baz2");
//return 'baz2'
//
printFirst();
//return Error
// TypeError: Cannot read properties of undefined (reading 'first')

Basically after instantiating newFoo being able to deconstruct the methods inside the class and use them while them keeping the reference of the params that were passed at the time newFoo was created

about 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!