Side navigation
#11480 closed bug (invalid)
Opened March 16, 2012 01:05PM UTC
Closed March 31, 2012 08:26AM UTC
Event handler (callback) does not receive the most-derived instance for non-dom element eventing.
Reported by: | tokensdragon | Owned by: | tokensdragon |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.7 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
The following code block functions correctly in 1.6.4 but performs incorrectly in 1.7, 1.7.1 and 1.7.2rc1
var Human = function () { $(this).unbind('speak').bind('speak', function (e) { $(this).trigger('beforespeak'); console.log('base speak'); }); $(this).unbind('beforespeak').bind('beforespeak', function (e) { console.log('base beforespeak'); }); this.onspeak = function (e) { console.log('base onspeak'); }; this.onbeforespeak = function (e) { console.log('base onbeforespeak. I should be called only when Human is instantiated but not when Worker instantiates since this should be overridden in Worker.'); }; }; var Worker = function() { $(this).bind('speak', function (e) { console.log('derived speak'); }); this.onspeak = function (e) { console.log('derived onspeak'); }; $(this).bind('beforespeak', function (e) { console.log('derived beforespeak'); }); this.onbeforespeak = function (e) { console.log('derived onbeforespeak. I should be called instead of base onbeforespeak. Immediately after base and derived beforespeak events.'); }; }; Worker.prototype = new Human(); Worker.prototype.constructor = Worker.prototype; var w = new Worker(); $(w).trigger('speak');
Expected console output:
base beforespeak derived beforespeak derived onbeforespeak. I should be called instead of base onbeforespeak. Immediately after base and derived beforespeak events. base speak derived speak derived onspeak
1.7x console output:
base beforespeak derived beforespeak base onbeforespeak. I should be called only when Human is instantiated but not when Worker instantiates since this should be overridden in Worker. base speak derived speak derived onspeak
Summary:
When adding a sequence of event callbacks and overriding a base object's event, the base object's event is called in error instead of the override in the derived object.
Attachments (0)
Change History (2)
Changed March 16, 2012 01:28PM UTC by comment:1
owner: | → tokensdragon |
---|---|
status: | new → pending |
Changed March 31, 2012 08:26AM UTC by comment:2
resolution: | → invalid |
---|---|
status: | pending → closed |
Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!
Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.
Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: http://jsfiddle.net/FrKyN/ Open the link and click to "Fork" (in the top menu) to get started.