TurboGears: MochiKit JavaScript library

# About MochiKit

# MochiKit in-an-instant

### Home page

mochikit.com

### Fearless Leader

Bob Ippolito

### Claim-to-fame

Makes JavaScript suck less

### What's so great?

Clean design, practical and easy functionality, documentation, automated tests

There are lots of JavaScript libraries out there. One of the first things you'll notice about MochiKit is that you're not left guessing about how to use it or what's in there. Unlike the vast majority of JavaScript libraries, there is actual English text to describe how to use it.

And, once you start looking at how to use the functions it contains, you'll see that there's a whole bunch of useful stuff in there. MochiKit's creator, Bob Ippolito, is well-known in Python circles and has created a library that is natural to use for both Python and JavaScript programmers. It provides functions for performing asynchronous operations (AJAX, anyone?), logging (unless you really love alert boxes!), working with lists of data (and who doesn't), plus some amazing DOM tools.

## See for yourself!

Sane sorting and pulling values out of a list is easy:

myObjectArray = [ {"a": 3, "b": 2}, {"a": 1, "b": 2} ]; // sort it by the "a" property, check to see if it matches myObjectArray.sort(keyComparator("a")); // get just the "a" values out into an array sortedAValues = map(itemgetter("a"), myObjectArray);

Creating a whole new table is a piece of cake:

var rows = [ ["dataA1", "dataA2", "dataA3"], ["dataB1", "dataB2", "dataB3"] ]; row_display = function (row) { return TR(null, map(partial(TD, null), row)); } var newTable = TABLE({'class': 'prettytable'}, THEAD(null, row_display(["head1", "head2", "head3"])), TFOOT(null, row_display(["foot1", "foot2", "foot3"])), TBODY(null, map(row_display, rows))); // put that in your document.createElement and smoke it! swapDOM(oldTable, newTable);

Return to About TurboGears.