Allow closure-less defining of scope for events
|Reported by:||natecavanaugh||Owned by:||brandon|
An issue that we're running into is that IE in particular uses quite a bit of memory when using closures to maintain object scope to use a method for an event on an element.
The use case is that it is often much better to organize code into objects and often the element itself is only a small part of the total work being done with an event.
Here is how I would propose the API (which is similar to the bindo plugin, however, that plugin uses closures, which suffer the same memory issues):
jQueryObject.bind('click', [obj, fn], data);
Basically, if the second parameter is an array, check if it contains an object to set the event scope to, and the second element of the array can be either the function itself or a string name. So both of these would work: jQueryObject.bind('click', [MyObject, MyObject.method]) jQueryObject.bind('click', [MyObject, 'method'])
Allowing this would greatly enhance larger applications to be able to maintain an object scope, and prevent anonymous functions from keeping a large set of variables in memory when they're not needed.
Thanks in advance,
Change History (5)
comment:1 Changed 8 years ago by flesler
- Cc natecavanaugh added
- Component changed from unfilled to event
- Owner changed from flesler to brandon