Bug Tracker

Modify

Ticket #11480 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

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:
Blocking: Blocked by:

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.

Change History

comment:1 Changed 2 years ago by sindresorhus

  • Owner set to tokensdragon
  • Status changed from new to pending

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.

comment:2 Changed 2 years ago by trac-o-bot

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

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!

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.