Bug Tracker

Modify

Ticket #5312 (closed bug: invalid)

Opened 4 years ago

Last modified 4 years ago

Unbind doesn't work if bound using an annoymous function in IE

Reported by: chrisprice Owned by: brandon
Priority: major Milestone: 1.4
Component: event Version: 1.3.2
Keywords: Cc:
Blocking: Blocked by:

Description

I'm posting this in case any one else comes across a similar problem, as it appears to be a bug in IE I don't think this is fixable in jQuery.

I would expect the following to run handler1 the first time $thing is clicked and handler2 the second time, handler1 the third time, etc...

$(function() {
  var $thing = $("body");
  $thing.click(function handler1() {
    alert(1 + handler1 + handler2);
    $thing.unbind("click", handler1).click(function handler2() {
      alert(2 + handler1 + handler2);
      $thing.unbind("click", handler2).click(handler1);
    });
  });
});

I believe this behaviour is due to the following two (non-jQuery) test cases -

var f = function g() {
 alert(f === g);
 alert(f == g);
};
f();
alert 1 alert 2
IE false false
FF true true
Chrome true true
function a(fn) { 
 alert((fn === fn) + (fn() === fn()) + (fn === fn())); 
}
a(function b() { return b; });
alert
IE 2
FF 3
Chrome 3

Attachments

IE bug.html Download (346 bytes) - added by chrisprice 4 years ago.
The non-jquery test cases

Change History

Changed 4 years ago by chrisprice

The non-jquery test cases

comment:1 Changed 4 years ago by dmethvin

You'd be better off using .toggle(fn1, fn2) anyway I would think.

comment:2 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Actually, since this isn't a jQuery bug I'll close it. If we had a bug for every strange thing IE does...

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.