magwo/elevatorsaga

Erroneous handling of floor

asm0dey opened this issue · 4 comments

Code like

    for (i = _i = 0, _len = floors.length; _i < _len; i = ++_i) {
      floor = floors[i];
      floor.on('up_button_pressed down_button_pressed', function(event) {
          console.log(event)
          console.log(i)
        activeFloors.push(i);
      });
    }

reports one floor every time. In my case it's 8

Looks like all events are being binded to one floor

No, your iterator is the one that reports '8'. You shouldn't be using 'i'
in the event handler function, try 'this' to get the floor object instead
On Jan 26, 2015 6:25 AM, "Paul" notifications@github.com wrote:

Looks like all events are being binded to one floor


Reply to this email directly or view it on GitHub
#42 (comment).

You're right, this works. But it looks like strange behaviour for me. Binding event listener isn't async action, is it?

Duplicate of #27