[whatwg] Progress Events "done" event

Garrett Smith dhtmlkitchen at gmail.com
Mon Sep 10 14:33:20 PDT 2007


On 8/27/07, Křištof Želechovski <giecrilj at stegny.2a.pl> wrote:
> Remember that JavaScript is a programming language after all.  You can use a
> loop to get rid of the repetitions.
> Start from
> var done = ["load", "error", "abort"]...
> and apply the closure image.aEL(?, hPB, false) to it.
> Sincerely,
> Chris
>
That is true, in fact, it would also be possible to use Array.forEach
on that array.

The disadvantage is that it still invites code repetition. It is less concise.

On the contrary:

xhr.addEventListener("done", callCompleteHandler, false);
function callCompleteHandler(e) {

}

Translates the use case to code quite naturally.


I like to make these examples that are conceptually similar:

"I'm going to call my friend and then I'm going to the dry cleaner."
vs.

"I'm going to call my friend and if she's not available, after that,
I'm going to the dry cleaner and if the call failed, after that, I'm
going to the dry cleaner, and if we talk for a bit, after that...

You get the point. English doesn't have loops or generators (hey
wouldn't that be cool!).

My point is that having a done event is more concise and makes
realizing the use-case requirement to code more explicit.

Garrett

> -----Original Message-----
> From: whatwg-bounces at lists.whatwg.org
> [mailto:whatwg-bounces at lists.whatwg.org] On Behalf Of Garrett Smith
> Sent: Sunday, August 26, 2007 8:25 AM
> To: whatwg at whatwg.org
> Cc: chaals at opera.com
> Subject: [whatwg] Progress Events "done" event
>
>
> ==========================================
> function showImage(imageHref) {
> ...
>
> // remove the progress bar when done.
>        image.addEventListener("load", hideProgressBar, false);
>        image.addEventListener("error", hideProgressBar, false);
>        image.addEventListener("abort", hideProgressBar, false);
> }
> ==========================================
>
> This is somewhat verbose. Clearly, the author is forced to repeat
> himself when all he really wants to do is hide the progress bar after
> the call is done.
>
>
>
>
>


-- 
Programming is a collaborative art.


More information about the whatwg mailing list