i am i am - 1 year ago 45
Javascript Question

Why does Chrome appear to fire user events?

I tried both

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() {
$(document).bind("click", self.intervalEnd());
}, 5000);

intervalEnd: function(){
console.log('intervalEnd called');

Answer Source

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