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

230
Views
Cómo eliminar/eliminar un objeto del juego

¿Cómo se crea un objeto que puede matarse/eliminarse a sí mismo? p.ej

 var bullet = []; function bullet() { this.removeSelf = () => { this = false; } } function setup() { bullet[0] = new Bullet(); bullet[0].removeSelf(); } setup();
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No estoy seguro si entendí tu pregunta correctamente, pero si quieres destruir el objeto y liberar la memoria, primero debes eliminar todas las referencias y luego el recolector de basura automáticamente hará el trabajo por ti.

Está almacenando una referencia al objeto en la matriz para que pueda hacer esto: bullet[0] = null

about 4 years ago · Santiago Trujillo Report

0

Si el objetivo es eliminarlo de la matriz principal, debe editar esa matriz. Entonces, podemos pasar el padre a la instancia y hacer que removeSelf busque su instancia en el padre y lo splice .

También cambié el nombre del constructor a Bullet .

 var bullets = []; function Bullet(parent) { this.removeSelf = () => { const index = parent.indexOf(this); parent.splice(index, 1); } } function setup() { bullets[0] = new Bullet(bullets); bullets[1] = new Bullet(bullets); // Add a second isntance to the array bullets[0].removeSelf(); } setup(); console.log(bullets.length) // Should be 1

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