Quote:
Originally Posted by johnmerlino
Is there a less repetitive way to do this? I guess a class method? Although, I thought that was the whole idea of prototyping it to String object, so I can call it on a string.
|
<script>var component = window.location.hash.replace('#', '');
alert("The component name is " + component);
if(!String.prototype.singularize){
String.prototype.singularize = function(){
var context = this;
result = ((context.charAt(context.length -1, 1) == 's') ? context.substring(0, context.length - 1) : context);
return result;
}
}
var component = component.singularize();
alert("The component name is " + component);
</script>