The jQuery documentation for both basically states the same thing so I was wondering if there’s any major difference, if any, between the two. Thanks!
The jQuery documentation for both basically states the same thing so I was wondering
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The documentation on this is actually really bad, so here’s what I found by studying the source code:
lockonly prevents futurefirecalls, but does not prevent functions to beadded.Here’s a quick rundown of the methods:
empty– Removes any callbacks registered thus far.lock– Prevents further calls tofire, but allows more callbacks to beadded.disable– Prevents further calls to bothfire&add.To understand all this, let’s start with an explanation of the
memoryflag:If the callback object is constructed with the
memoryflag, it’ll keep track of the lastfirecall, and any callback added later will immediately be called. Here’s an example:This’ll also log second, even though it was added after the
firecall.If you
disableit though, it’ll completely wipe the memory. Here’s another example:This’ll only log first, since
callbackshas been disabled before the second function was added.However, if you use
lockit instead, functions added later will be called. Here’s another example:This’ll also log second, but only once; since the object was
locked, any further calls tofirewill be ignored.