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.
-
Archives
- September 2018
- February 2017
- October 2015
- December 2013
- February 2013
- December 2012
- November 2012
- September 2012
- August 2012
- April 2012
- March 2012
- January 2012
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- April 2010
- March 2010
- February 2010
- January 2010
- December 2008
- July 2008
- February 2008
-
Meta
Which build # has this been available since?
And does it actually mean one object less to be garbage collected, or just syntactic sugar?
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.