/ Published in: JavaScript

Expand |
Embed | Plain Text
String.prototype.camelize = function( ) { return this.replace( /-([a-z])/g, function( $0, $1 ) { return $1.toUpperCase( ) } ); } alert( "get-element-by-id".camelize( ) ); //getElementById
Comments

You need to login to post a comment.
It could also be done without modifying the prototype like this: function camelize(str) { return (str + "").replace(/-\D/g, function(match) { return match.charAt(1).toUpperCase(); }); }