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:Michael Geary (M.@Geary.com)
Date:Mar 28, 2006 9:14:36 am
List:com.googlegroups.jquery-en

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.

Sure. The actual code was:

if( [0,1,1,1,0][xml.readyState] ) { ... }

The key to understanding this is to remember that an array literal constructs an Array object, so you can index it, call methods on it, etc.

It may look more familiar if we split it into individual statements:

var array = [0,1,1,1,0]; var flag = array[xml.readyState]; if( flag ) { ... }

As another example, I have practically given up string concatenation in favor of the faster Array.join(). Instead of:

var msg = 'values: ' + val1 + ' ' + val2 + ' ' + val3;

I now use:

var msg = [ 'values:', val1, val2, val3 ].join(' ');

All of the JavaScript literal constants work this way. Here's an Object example from my own code. Given a variable named 'type' whose value is either 'Smooth' or 'Page', I want to return a string '1' for 'Smooth' or '2' for 'Page'. I can do it like this:

var result = { Smooth:'1', Page:'2' }[type];

-Mike