Too much recursion 

Higher Order Javascript

 



   Subscribe in NewsGator Online    Subscribe in Rojo    Add to Google      Add to My AOL   Subscribe in FeedLounge   Add to netvibes  

Brendan Eich's Roadmap  Standard ECMA-262  www.schillmania.com  www.quirksmode.org 
www.snook.ca  www.davidflanagan.com  www.kryogenix.org  www.thomasfrank.se 
www.dustindiaz.com  Yahoo! UI Library  www.crockford.com  www.brainjacked.com 
chadlindstrom.ca  www.browserland.org     
       

Sunday, September 17, 2006

 

goodbye expando hello addData, getData


Why are expando's needed? To hold data. Sometimes, the data is another node(bad for ie). So how do we store data about an element? Say a div wants to know who its 2 'brother nodes' are, or an element wants to keep track of its size changes? Whatever, check this out:

String.prototype.addData= String.prototype.ad = function(n,v){
if (!window.elData){window.elData=[]}
if( !elData[this] ){ elData[this]=[] }
if( !n ){ elData[elData.length++]=this }else{ elData[this][n]=v };
return this;
};
String.prototype.getData= String.prototype.gd = function(n){
return( n )? elData[this][n] : elData[this];
};

Now add all the data you want. Say the div previously mentioned has an id of 'blah':
'blah'.ad('b1','divb1id').ad('b2','divb2id');
el.id.ad(size);

Getting the data is also easy:
b1= 'blah'.gd('b1'); b2= 'blah'.gd('b1');
getSizeHistory=el.id.gd();

This can also be used for classNames, function args...

Comments: Post a Comment

Links to this post:

Create a Link



<< Home

Archives

June 2006   July 2006   August 2006   September 2006  

This page is powered by Blogger. Isn't yours?