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



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(/-/) ){ }
styleObj[ selector ]= propAndVal[1].toLowerCase()}; return styleObj;
String.prototype.camelCase= = 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


June 2006   July 2006   August 2006   September 2006  

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