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

329
Views
Javascript clone () no es un error de función

Estoy trabajando en un juego js e intento clonar un objeto, pero sigo teniendo este error:

this[i].clone is not a function

este es mi codigo:

 Object.prototype.clone = function() { var i, newObj = (this instanceof Array) ? [] : {}; for (i in this) { if (i === 'clone') { continue; } if (this[i] && typeof this[i] === "object") { newObj[i] = this[i].clone(); } else { newObj[i] = this[i]; } } return newObj; };

Traté de reemplazar 'clon' con esta solución:

JSON.parse(JSON.stringify(object)) no funcionó. ¿alguna ayuda por favor?

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

0

parece como funciona

 Object.prototype.clone = function() { var i, newObj = (this instanceof Array) ? [] : {}; for (i in this) { if (i === 'clone') { continue; } if (this[i] && typeof this[i] === "object") { newObj[i] = this[i].clone(); } else { newObj[i] = this[i]; } } return newObj; }; var person = { name: 'John', address: { city: 'New York' } }; var clonedPerson = person.clone(); person.address.city = 'Buenos Aires'; console.log(person.address.city); console.log(clonedPerson.address.city);

¿Cómo es tu llamada?

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!