proxy and unbind don't play well with each other

proxy and unbind don't play well with each other

Hi All,

I have attached a sample page that demonstrates a jQuery event binding problem that we are having with our code (note that it needs John Resig's patch to fix event binding on plain objects which I've included in the zip: http://github.com/jquery/jquery/commit/7f5179b65431b77e89fa32623a5000e3630c191c ). We know why the code breaks, but think that it is an oversight/bug in how unbind removes handlers from the listeners list. Basically when proxy generates guids for the proxy functions, it reuses the same guid regardless of passed in context. unbind then later uses the guid of the passed in handler to remove *all* proxies of the source function when in reality you only wanted one.

The output of the test is written to the FireBug console and should be as follows:

change event triggered for item with id: objA
change event triggered for item with id: objB
change event triggered for item with id: objB

whereas currently it writes out:

c hange event triggered for item with id: objA
change event triggered for item with id: objB

There is a couple of workarounds for this: namely stop using proxy and use something like prototype js's bind or use namespaced events (again, create a unique namespace for each instance of an object). Neither of these seems like a very clean solution though. I think ultimately, the guid stuff on proxy and unbind needs to be thought about a bit.

I hope I've explained the problem clearly enough, but if not, feel free to ask any questions.

Thanks for any help in advance,
Sahab Yazdani

[UPDATE]: Fix the link to the patch.