Recursion

Just replaced a ton of stuff like this:

function topOffset(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    do {
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return curtop;
  }
  return 0;
}

With this:

function topOffset(obj) {
  return obj ? obj.offsetTop + topOffset(obj.offsetParent) : 0;
}  

Feels good.


Here’s a bit more of a mind-cruncher if anyone feels like mental exercise:

  var nextCell = (function f(c, d) {
                    return c && (c.depth <= d ? c : (c.next && f(c.next, d)));
                  })(currentCell.next, currentCell.depth)