every time i encounter this word i wonder what it really means. eg an event handler, is that a function?
$('a').click(function(){ ... });
is the click an event. and the handler the anonymous function?
every time i encounter this word i wonder what it really means. eg an event handler, is that a function?
$('a').click(function(){ ... });
is the click an event. and the handler the anonymous function?
function is a generic word, if the function it does is handling an event then the function becomes an event handler.
A function is a language construct. It becomes a handler depending on how you use it. When a function is registered with an event, it's an event handler. There are other examples of roles functions can play: a constructor is called when constructing an object, a callback is a function passed as a parameter to another function to call, and so on.
You're right and it usually works like this:
function somefunc(handler) {
// do some lengthy tasks then notify handler
handler();
}
somefunc(function(){ alert('test'); });