Err, brace madness. Should be:
function to an intermediate function. In code:
for (var i = 0; i < 5; i++) {
function getHandler(arg) {
return function() {
alert(i);
}
}
button.addEventListener("click", getHandler(i), false);
}
You can of course move getHandler() outside the loop to make it more
readable. There is also a general form called partial() which is
implemented in MochiKit if you want to have a look at that.
- a
On 5/30/06, Aaron Boodman <[EMAIL PROTECTED]> wrote:
You need to pass the value that should be passed to the dynamic
- a
On 5/30/06, Nickolay Ponomarev <[EMAIL PROTECTED]> wrote:
> On 5/30/06, Didier Ernotte <[EMAIL PROTECTED]> wrote:
> > Maybe?
> >
> > button.setAttribute("ident", ixyzt);
> > button.addEventListener('click', function (event){
> > foo(event.target.getAttribute("ident")}, 'false');
> > ixyzt++;
> >
> > Didier
>
> That's correct solution, but the last param to addEventListener should
> be a boolean, not a string. (Your 'false' gets passed as true
> actually.)
>
> Nickolay
> _______________________________________________
> Project_owners mailing list
> [email protected]
> http://mozdev.org/mailman/listinfo/project_owners
>
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners