Ted Tzuridis Ted Tzuridis - 1 year ago 74
Node.js Question

Why isn't my reset function stopping?

My reset button continues to clear the canvas and empty the chat box. Shouldn't the return statement end the function?


var reset = function() {
context.clearRect(0,0, canvas[0].width, canvas[0].height);
socket.emit('reset', reset);

$('#reset').on("click", reset);

socket.on('reset', reset);


socket.on('reset', function(){

Answer Source

At the end of your reset function, you're emitting a reset event.

socket.emit('reset', reset);

You've also setup a handler for when the reset event is emitted.

socket.on('reset', reset);

So every time you call reset, you're emitting an event which ends up calling reset again.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download