twitter/flight — pull request #21 by scottrabin (2013-02-03 22:58:44+00:00)
Title: `this.off` does not correctly detach callbacks bound more than one time

Fiddle demonstrating this issue (against master): http://jsfiddle.net/scottrabin/Vb89D/1/

When multiple events are bound to the same callback function, attempting to remove the events via `this.off(sameElem, sameEvent, fn)` does not correctly remove the bound event.

This pull request introduces the fix (copy the `guid` assigned to the original callback, if it exists, to the context-bound callback generated during `component.on(...)`) as well as a test case for this bug.

_Commit Notes:_
Copy function `guid` to context-bound version

jQuery internally relies on unique `guid` values to ensure that the
correct function is removed from an element in `$(element).off('event',
func);`. Previously, `component.on` would attach the `guid` value to the
original callback to preserve this functionality in jQuery. However,
future calls to `.on('event', sameFunc)` would fail to check the
original callback for this `guid` value and simply overwrite it with
whatever new `guid` was assigned by jQuery. This change preserves the
original `guid` value across multiple calls to `on` with the same
function.