i am i am - 2 months ago 10
Javascript Question

Why does Chrome appear to fire user events?

I tried both

mousemove
and
click
and the event always fires on page load.

I even tried to put a 5 second delay on the bind, and the event still fires.

setTimeout(function() {
console.log('click');
$(document).bind("click", self.intervalEnd());
}, 5000);

},
intervalEnd: function(){
console.log('intervalEnd called');
console.log(this.intervalID);
window.clearInterval(this.intervalID);
},

Answer

No, the event doesn't fire on pageload, but your function does execute on pageload, because that's what you told it to do.

Reference the function, instead of calling it, and use on()

$(document).on("click", self.intervalEnd);

Whenever you add parentheses to a function, you call it and return the result, so your code is the same as

var result = self.intervalEnd(); // most likely returns undefined
$(document).bind("click", result); // still undefined
Comments