Skip to main content

Bug Tracker

Side navigation

#5411 closed bug (invalid)

Opened October 27, 2009 04:30PM UTC

Closed October 27, 2010 10:21PM UTC

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@hotmail.com
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.

Attachments (0)
Change History (1)

Changed October 27, 2010 10:21PM UTC by rwaldron comment:1

priority: majorlow
resolution: → invalid
status: newclosed

The test case contained incorrect code to achieve the desired result.

Correct:

http://jsfiddle.net/rwaldron/D2ECC/1/