[jQuery] New filter :alternate + IE leaking
Hello,
I have to say I'm addicted to jQuery.
I wanted to try and enhance the alternate children selection for jQuery,
i.e. for alternating row coloring for tables and not only.
So instead of doing this:
$('tr:nth-child(odd)').addClass('odd');
I wanted to do something general like:
$('tr:alternate(3,1)').addClass('row1');
$('tr:alternate(3,2)').addClass('row2');
$('tr:alternate(3,3)').addClass('row3');
Where the first parameter for alternate is the total number of items in
a group and the second one is the nth item in a group. So this
$('tr:nth-child(odd)').addClass('odd');
is the same with
$('tr:alternate(2,1)').addClass('row3');
I've put up a test page here: http://agachi.name/tests/jquery/alternate.htm
*IE leaks* :(
While working with jQuery for the past weeks now, I've been hitting on
the IE memory leaking problem. I've read a lot of articles about this
issue, and still couldn't find a solution for a simple problem like this
one. When implementing the above feature, I've created a function which
uses closures some thing like:
$(...).each(function(){ this.$alternateHover = clsh[i-1]; }).
bind('mouseover', function(){
$(this).addClass(this.$alternateHover); }).
bind('mouseout', function(){
$(this).removeClass(this.$alternateHover); });
This will leak in IE. Why?
Neither closures reference a DOM node.
I've also inserted a modified script which will null-ify every event
handler on unload (original here: http://youngpup.net/2005/0221010713)
I rewrote this using functions defined as new Function(...) so the
following script will not leak:
$(...).each(new Function("this.$alternateHover='" + clsh[i-1] + "';")).
bind('mouseover', new
Function("$(this).addClass(this.$alternateHover);")).
bind('mouseout', new
Function("$(this).removeClass(this.$alternateHover);"));
Online here:
http://localhost/_test/js/jQuery/tests/alternate-not-leaking.htm
Could anyone give an answer to why this will leak in IE?
What will be the answer to no IE leaking issues? Writing function as new
Function(...), and throwing away the power of closures?
--
*Valentin Agachi*
Web developer
agachi.name <http://agachi.name/>
Anunta-ma.ro <http://www.anunta-ma.ro/>
*Tel:* +40-721-657509
*Hotmail:* avaly2k@hotail.com
*Gmail:* valy.agachi@gmail.com
*Y!:* valentin.agachi@yahoo.com
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/