jquery-timing Show archive.org snapshot is a very useful jquery plugin that helps to remove lots of nested anonymous functions. It's API provides you some methods that help you to write readable and understandable method chains. See yourself:
// before
$('.some').show().children().doThat();
window.setTimeout(function(){
$('some').children().doSomething().hide(function() {
window.setTimeout(function() {
otherStuffToDo();
}, 1000);
});
}, 500);
// after
$('.some').show().children().doThat() .wait(500) .doSomething().hide() . wait(1000) . otherStuffToDo();
jquery-timing transformed the setTimeout
callback into a chainable method. Now the code is easier to read and understand.
Image you need to show another node 10 seconds after the hide animation completed. Normally you would pass an anonymous function to hide()
.
With jquery-timing you can chain your methods and don't need to break the flow.
jquery-timing can help you out in lots of situations (e.g. timeouts, intervals, event callbacks, ...).
Here's an excerpt of
usage examples
Show archive.org snapshot
:
Hint: You should also have a look at deferred objects (promises pattern) Show archive.org snapshot , the refactored jQuery AJAX Show archive.org snapshot component and some articles Show archive.org snapshot about jQuery deferreds Show archive.org snapshot .