MS Ajax adds String.format method to Javascript
Came across this little gem today. I've always hated string concatenation in javascript. I know there are performance issues related to string building in javascript, but that was the least of my concern. It is just too damn hard to read and maintain code
var input = '<input type="radio" id="' + this.name.value + i.toString() + '" name="' + this.group.value + '" value="' + this.value.toString() + '" />;
MS Ajax has a String.format function that behaves similar to the server side version where you get to do the nice little {0} string replacements. It makes code much easier to read. And code that is easier to read and maintain is cheaper code (read: cost effective).
The same string written above looks so much nicer using String.format.
var input = String.format( '<input type="radio" id="{0}" name="{1}" value="{2}" />'
, this.name.value + i.toString()
, this.group.value
, this.value.toString() );
I hope this adds a little bit of readability and reduces the level of frustration when dealing with javascript and counting ' and " to close out strings. I really want a javascript validator/compiler.