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

141
Views
¿Tiene un elemento HTML un prototipo (como Element.prototype.myFunc)?

Estoy tratando de hacer animaciones, y quiero poder hacer esto:

 document.getElementById("item").move()

en lugar de esto:

 move(document.getElementById("item"))

Intenté lograrlo con Object.prototype.move, pero no funcionó.

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

0

Un DOM HTMLElement es un Object , por lo que debería funcionar, sin embargo, un Object no es necesariamente un HTMLElement , por lo que debe agregar ese método a HTMLElement.prototype en su lugar:

 HTMLElement.prototype.move = function() { let position = 0; const self = this; function render() { self.style = `left: ${position++}px`; requestAnimationFrame(render); } requestAnimationFrame(render); } document.getElementById('square').move();
 #square { position: fixed; height: 20px; width: 20px; background-color: blue; }
 <div id="square"> </div>

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!