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

 

String.prototype.cssObj


String.prototype.cssObj( styleObject[Object][optional] )
String.prototype.cssObj= function( styleObj ){ styleObj = styleObj || {};
var pairs=this.replace( /(^\s*)|(;\s*$)/g, '' ).split( /\s*;\s*/ ),selector,propAndVal,i=pairs.length;
while( i-- ){ propAndVal= pairs[i].split( /\s*:\s*/ );
selector=propAndVal[0] ;if( selector.match(/-/) ){ selector=selector.cc() }
styleObj[ selector ]= propAndVal[1].toLowerCase()}; return styleObj;
};
String.prototype.camelCase= String.prototype.cc = function(){
return this.replace(/-\D/gi, function(match){return match.charAt(match.length - 1).toUpperCase()} );
};


This code fits in wonderfully with many of the dom creation functions around, like the one on here. Example:
var s={ backgroundColor:'#f00',position:'absolute', width:'50px', height:'50px'};
'padding:5px; border-width:4px; border-style:solid; border-color:#333'.cssObj(s);

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?