- From: Hans Muller <hmuller@adobe.com>
- Date: Fri, 24 Feb 2012 09:36:58 -0800
On 2/23/12 5:23 PM, "Boris Zbarsky" <bzbarsky at MIT.EDU> wrote: >On 2/23/12 7:38 PM, Hans Muller wrote: >> Hans - It's useful if you want your listener to run after all of the >>load listeners have run, and code that you haven't written adds its own >>load listeners. > >I strongly urge you to read >http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx > >Or put another way, what will you do a year after this is standardized, >when the code that you haven't written is adding loadend listeners? If loadend listeners were used as intended and not as a proxy for "code to run last, after everything else", then years from now I'll carry on using them to run code after the load and error listeners have run. That said, I understand your point. To use loadend in the scenario I posed, you have to know that the function you're calling is doing something with load/error listeners that you'd like to follow with your own listener. > >>The problem with using setTimeout() to schedule a listener to run after >>all of image's load listeners has run is that you've got to guess how >>long >>loading the image (or failing to load the image) and running its >>listeners >>will take. > >No, you don't. You simply do: > > function delayedLoadStuff() { > setTimeout(doTheThingIWant, 0); > } > img.addEventListener("load", delayedLoadStuff, false); > img.addEventListener("error", delayedLoadStuff, false); Good point, although this approach seems to lead to the very same dystopia you were just warning about. If everyone tries to schedule their image listener last with setTimeout()... - Hans
Received on Friday, 24 February 2012 09:36:58 UTC