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  Yahoo! UI Library     

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= = 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= = 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':

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

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

Comments: Post a Comment

Links to this post:

Create a Link

<< Home


June 2006   July 2006   August 2006   September 2006  

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