atom feed22 messages in com.googlegroups.jquery-en[jQuery] Memory leaks forever
FromSent OnAttachments
Franck MarciaMar 25, 2006 7:13 am 
Dave MethvinMar 25, 2006 8:55 am 
Franck MarciaMar 25, 2006 9:08 am 
John ResigMar 25, 2006 9:15 am 
Dave MethvinMar 25, 2006 10:07 am 
Michael GearyMar 25, 2006 10:07 am 
Franck MarciaMar 25, 2006 10:39 am 
Michael GearyMar 25, 2006 10:56 am 
Dave MethvinMar 25, 2006 11:05 am 
Franck MarciaMar 25, 2006 1:45 pm 
Michael GearyMar 25, 2006 2:19 pm 
Franck MarciaMar 25, 2006 5:16 pm 
Dave MethvinMar 26, 2006 9:02 am 
Michael GearyMar 26, 2006 1:24 pm 
Franck MarciaMar 28, 2006 2:25 am 
Dave MethvinMar 28, 2006 5:45 am 
John ResigMar 28, 2006 7:30 am 
Franck MarciaMar 28, 2006 8:26 am 
jqu...@vikas.mailshell.comMar 28, 2006 8:57 am 
John ResigMar 28, 2006 9:03 am 
Michael GearyMar 28, 2006 9:14 am 
jqu...@vikas.mailshell.comMar 28, 2006 9:24 am 
Subject:[jQuery] Memory leaks forever
From:John Resig (jere@gmail.com)
Date:Mar 28, 2006 9:03:59 am
List:com.googlegroups.jquery-en

Essentially, he wants to say:

if ( xml.readyState == 1 || xml.readyState == 2 || xml.readyState == 3 ) { ... do some stuff because the xml isn't loaded yet }

The nice fact that he took advantage of was that xml.readyState can only have four possible values (1-4), so he put them in an array, with each value being true or false. So, if we break it down, it could look like this.

var lookup = new Array( false, true, true, true, false ); var currentNumber = xml.readyState;

alert( lookup[currentNumber] );

If the number is 1, 2, or 3 it will return true. For anything else, it returns false ( or a value equal to false).

One thing that he takes advantage of is the fact that 0 and 1 are also equal to false and true, making the code even shorter.

Finally, he takes advantage of the fact that you can define arrays using [...] and look up data in them on the fly.

That's a really long description for code that is so short - hope that helps!

--John

On 3/28/06, jquery at vikas.mailshell.com <jquery at vikas.mailshell.com> wrote:

--- John Resig <jeresig.at.gmail.com at jquery.at.vikas.mailshell.com> wrote:

Sorry, I'm just mesmerized by this code: [0,1,1,1,0][xml.readyState] that's seriously one of the coolest boolean ideas that I've seen.

For the rest of us out there, can someone kindly break that little snippet into plain English? It looks like nothing I have ever seen before.

Thanks