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

168
Views
¿Es posible definir un objeto que mantenga y manipule sus propios valores?

¿Algo en esta dirección? Aquí los trabajos no están definidos en las funciones addJob y runNext, ¿existe la posibilidad de obtener este trabajo?

 const myThing = { jobs: [], addJob: (id, job) => { jobs.push({id: id, job: job}) }, runNext: () => { jobs.shift().job() } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar una función de fábrica o una clase para lograr esto:

Función de fábrica:

 function myThing() { const jobs = []; return { addJob: (id, job) => { jobs.push({ id: id, job: job }) }, runNext: () => { jobs.shift().job() }, print: () => { console.log(jobs); } }; } const instance = myThing(); instance.addJob("someId", "someJob") instance.print();

Clase:

 class MyThing { jobs = []; addJob(id, job) { this.jobs.push({ id: id, job: job }); } runNext() { this.jobs.shift().job() } print() { console.log(this.jobs); } } const instance = new MyThing(); instance.addJob("someId", "someJob"); instance.print();

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!