Taken from this talk:
http://www.youtube.com/watch?v=GKfHdOrR3lw

By returning false we are letting the browser know that the usual behavior is being overridden:

<pre>$("a#next").click(function(){
$("#message").show();
return false;
});

Chaining: Most function calls return the same object as opposed to returning void, so that lots of things can be done in a single chain, as in:

var searchbar = $("#searchbar");
searchbar.keydown(
//...
).val(miso.constants.SEARCH_PROMPT).click(
//...
).autocomplete(
//...
).data("autocomplete")._renderItem = function(ul, item) {
 return $("<li></li>").data("item.autocomplete", item).append("<a>" + item.label + "</a>").appendTo(ul);
 };

Another example showing the use of .end() for operating the entity stack:

$("ul.open") // [ul, ul, ul]
.children("li") // [li, li, li]
.addclass("open") // [li, li, li]
.end() // [ul, ul, ul]
.find("a") // [a, a, a]
.click(function() {
//do something
}) // [a, a, a]
.end() // [ul, ul, ul]

Advertisements