[dokuwiki] Re: [OFFTOPIC] odd addEvent problem

  • From: Andreas Gohr <andi@xxxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 2 Aug 2006 20:11:31 +0200

On Wed, 2 Aug 2006 10:48:56 +0200
Michael Klier <chi@xxxxxxxxxxx> wrote:

> > The idea is to force the argv to be out of the loop scope into the 
> > buttonAttach function scope. No idea if this really changes
> > anything.
> 
> That was it :-D! Now it works the way it should although it`s odd to
> me anyway (JS is sometimes really strange to me).
> 
> Thanks for your help Andi.

Thinking about it again I think there may be a simpler solution. Could
you try this:

attachToolEvents: function(obj) {
   ...
   for(var i=0;i<tool_btns.length;i++) {
         var argv   = '';
         ...
         // attach the Event
         addEvent(button,'click',function() { return
              calendar.show(argv); });
   }
   ...
}

The var keayword should make the argv local to the current loop
iteration and do exactly the same but without the need for the second
function.

Andi

Other related posts: