Undo and redo is a fairly interesting and surprisingly difficult concept to implement in an application. Thanks to the way javascript treats functions, it isn't too hard to come up with a general and powerful approach for javascript apps.
undone([
function () {
// undo
},
function () {
// redo
}
]);
undone(0); // => undo
undone(1); // => redo
if-else shorthand ?: can be used to shave 7 bytes off this one: