[Project_owners] [JS] addEventListener function parameter

Aaron Boodman zboogs at gmail.com
Tue May 30 14:59:48 EDT 2006


Jeez, I can't type today. That should have been:

for (var i = 0; i < 5; i++) {
  partial(handleClick, i);
}

or, you can do it inline with an anon function like:

partial(function(arg) {
  // do stuff w/ arg
}, i);

I think the main argument against this is that it can cause memory
leaks. This is a fair complaint. I prefer to take the chance and later
debug the leaks, since I greatly prefer this form and since the leaks
are mozilla bugs that should hopefully someday go away.

But like I said, I'm interested in counter arguments.

- a

On 5/30/06, Aaron Boodman <zboogs at gmail.com> wrote:
> On 5/30/06, Nickolay Ponomarev <asqueella at gmail.com> wrote:
> > - but you're better off not using this unless you understand how it
> > works. (And it's really unnecessary if all you need to pass is a
> > simple string).
>
> eh... I prefer this form. I think tacking attributes onto random
> elements to store state is, err, tacky and has more chance to collide
> with other people's random additions. Also, with bind() it is really
> quite elegant:
>
> for (var i = 0; i < 5; i++) {
>   button.addEventListener("click", bind(i); i++);
> }
>
> Finally, I've read that attributes are quite expensive in mozilla,
> since they can be tied to CSS, XBL, etc.
>
> Why do you think it's better to store something in the DOM rather than
> in pure JS?
>
> - a
>


More information about the Project_owners mailing list