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ó.
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>