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

194
Views
¿Por qué mi última entrada de cliente anula la entrada anterior en lugar de agregarla al objeto de cliente? JS

¿Por qué mi última entrada de cliente anula la entrada anterior en lugar de agregarla al objeto de cliente? JS Cualquier ayuda sería muy apreciada.

 class Bank { constructor() { this.customers = {}; } } Bank.prototype.addCustomer = function (customer) { this.customers = customer; return this; } var bank = new Bank(); var newCustomer1 = bank.addCustomer('Curtis'); var newCustomer2 = bank.addCustomer('Alice'); console.log(bank.customers);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Primero, los clientes no son una matriz, la ha declarado como un objeto Javascript. En segundo lugar, cuando lo cambie a una matriz, use el método push para agregar elementos al final de la matriz.

He cambiado tu código en consecuencia.

 class Bank { constructor() { // Change 2 this.customers = []; } } // Change 2 Bank.prototype.addCustomer = function (customer) { this.customers.push(customer); } var bank = new Bank(); bank.addCustomer('Curtis'); bank.addCustomer('Alice'); console.log(bank.customers);
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!