Skip to content

Instantly share code, notes, and snippets.

@vstarck
Created August 22, 2011 19:56
Show Gist options
  • Save vstarck/1163358 to your computer and use it in GitHub Desktop.
Save vstarck/1163358 to your computer and use it in GitHub Desktop.
Camelize Decorator
// Decora la funcion camelizando su resultado
function camelizeDecorator(fn) {
return function() {
return fn.apply(null, arguments).replace(/[-\s_]+(.)?/g, function(match, chr) {
return chr ? chr.toUpperCase() : '';
});
}
}
function k(a) {
return a;
}
camelizedK = camelizeDecorator(k);
camelizedK('esto_es un-string'); // "estoEsUnString"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment