0

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!

asked Feb 27, 2013 at 18:05
9
  • 3
    This is the click event itself Commented Feb 27, 2013 at 18:07
  • A very general explanation (ignoring the fact that this is an event handler): You pass a function into the slides.paginator.click function. The slides.paginator.click will call your function when a click occurs. The e is simply parameter in the function that you pass in, and slides.paginator.click will supply the appropriate argument later. Commented Feb 27, 2013 at 18:08
  • 1
    "...how do I know that the click handler will provide such an event". By reading API documentation. Commented Feb 27, 2013 at 18:18
  • 1
    In the .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. Commented Feb 27, 2013 at 18:21
  • 1
    Here’s a link to the docs where jQuery explains all of it’s event object properties: api.jquery.com/category/events/event-object Commented Feb 27, 2013 at 18:22

1 Answer 1

2

"e" comes from "event", check the jquery .click() docs http://api.jquery.com/click/

function(e){} replaces "handler(eventObject)"

answered Feb 27, 2013 at 18:12
Sign up to request clarification or add additional context in comments.

3 Comments

I see. Well, how do I know what is being passed in that eventObject that I can reference? I notice 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.
cehck the docs for the eventObject api.jquery.com/category/events/event-object you can see the values and the methods you can call on it, you could use a browser inspector to watch the e object to understand it better
Yep, just ran across this as well. Your answer was exactly what I was looking for. Thanks for your help!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.