Opened 14 years ago
Closed 13 years ago
#5411 closed bug (invalid)
Cannot use prototype methods for event handler
Reported by: | dinoboff | Owned by: | brandon |
---|---|---|---|
Priority: | low | Milestone: | 1.4 |
Component: | event | Version: | 1.3.2 |
Keywords: | Cc: | dinoboff@… | |
Blocked by: | Blocking: |
Description
Here is the test:
test("Use prototype method as event handler", function(){ var $elem = $('#swipeTarget'), SomeConstructor = function($elem) { $elem.bind('test', this, this.handler); }; SomeConstructor.prototype = { handler: function() { var that = event.data; ok(true, "Called.");} }; expect(2); obj1 = new SomeConstructor($elem); obj2 = new SomeConstructor($elem); $elem.trigger('test'); });
The test will fail. Only obj2.handler will be called.
jQuery tracks event handler (for unbind) by adding them an unique guid property, and only one guid / element / event can be registered. In this case obj1.handler and obj2.handler are the same function and share the same guid.
Change History (1)
comment:1 Changed 13 years ago by
Priority: | major → low |
---|---|
Resolution: | → invalid |
Status: | new → closed |
Note: See
TracTickets for help on using
tickets.
The test case contained incorrect code to achieve the desired result.
Correct: http://jsfiddle.net/rwaldron/D2ECC/1/