I've got a piece of code I'm working with that was handed down to me by a previous developer. I am just trying to understand it better and not just use it naively. Here's the code:
slides.paginator.click(function (e) {
e.preventDefault();
interval.stop();
switchSlide($(this).index());
interval.start();
});
The part that I do not understand is the argument e that is being passed through this anonymous function. I have seen this before and I thought it had something to do with closures, but again, I am not sure. Can anyone give me a little insight into exactly how this parameter e works? I have seen it in other cases as well, such as with jQuery's AJAX methods.
Even pointing me in the right direction towards an article would be a great help. Thanks!
1 Answer 1
"e" comes from "event", check the jquery .click() docs http://api.jquery.com/click/
function(e){} replaces "handler(eventObject)"
3 Comments
e.preventDefault(); is being called, which I know stops the default behavior from happening. Now that I think about it, maybe that's just it.
slides.paginator.clickfunction. Theslides.paginator.clickwill call your function when a click occurs. Theeis simply parameter in the function that you pass in, andslides.paginator.clickwill supply the appropriate argument later..click()docs, you'll see:.click( handler(eventObject) )This is a description of the signature of the.click()method. It shows that it expects to receive a function to which an eventObject will be passed when invoked.