I hit a minor roadblock trying to see how I could get an object reference from within an object. Tom Trenka whipped up a quick little function (which is so obvious after you see it 🙂

function getObjectString(obj, scope) {
  for (var p in scope) {
    if (scope[p] == obj) return p;
  }
  return null;
}

It’s messy and O(n), true, but unless you have a mess of variables, not too bad.

Jesse made a suggestion on how I could avoid needing the string completely by assigning an IFrame.onload, but there are race conditions (unless you use event attachment, see below), and also Mozilla was giving me crap (is it running the onload before the document is finished?)

It occurred to me that there are lots and lots of little JS snippets like Tom’s which are enormously useful helpers, but hard to keep track of. Perhaps they should all go in a little snippets library/repository or something…