Skip to content Skip to sidebar Skip to footer

Event Handler Function In Prototype's Method, Why Does It Think .keycode Is A Property Of Undefined In Javascript?

I am experimenting with DOM event handlers, and I put in my Constructor's prototype a function that works on the DOM div element, which is a property created by the constructor in

Solution 1:

you're calling your method(with a not defined event argument) in your addEventListener call instead of passing it.

addEventListener("keyup", me.move(event));

should be

addEventListener("keyup", me.move);

to have access to your this property you need to bind the function aswell:

addEventListener("keyup", KeyBlock.prototype.move.bind(me));

Post a Comment for "Event Handler Function In Prototype's Method, Why Does It Think .keycode Is A Property Of Undefined In Javascript?"