JS runnables: now with less boilerplate

Actually, this little trick has been possible for at least a year and a half since I fixed the enhancement request, but I don’t believe it’s common knowledge. When writing something like
someEventTarget.dispatch({ run: function() { ... }), you can simply use someEventTarget.dispatch(function() { ... }) and skip the object goop. It looks cleaner to my eyes, so I thought I’d try to get the message out.

2 Responses to “JS runnables: now with less boilerplate”

  1. Which build # has this been available since?

    And does it actually mean one object less to be garbage collected, or just syntactic sugar?

  2. Firefox 4 has it; bug 540665 seems to have the wrong target milestone though.

    There are pros and cons to using functions. If you use a local function, it will entrain the scope. If you use a global function, you won’t be able to use any local state. But you can construct a global object and thus give it state without entraining the scope.

Leave a Reply