Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    189
    Thanks
    38
    Thanked 3 Times in 3 Posts

    firebug: component.singularize is not a function

    Hey all,

    Firebug gives me the below error message:

    component.singularize is not a function
    [Break on this error] var component = component.singularize();

    This is what I have:
    Code:
    		var component = window.location.hash.replace('#', '');
    		var component = component.singularize();
    		
    		alert("The component name is " + component);
    		
    		
    		
    		var singularize = function(){
    			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;
    				}
    			}
    		}
    Thanks for any response.

  • #2
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    92
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Code:
    <script>var component = window.location.hash.replace('#', '');
    		
    		
    		alert("The component name is " + component);
    		
    		
    		
    		var singularize = function(){
    			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;
    				}
    			}
    		}
    singularize();
    var component = component.singularize();
    alert("The component name is " + component);
    </script>

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    189
    Thanks
    38
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Shaka Zorba View Post
    Code:
    singularize();
    var component = component.singularize();
    Why would you need to call the function (singularize() and then call the function again (component.singularize()?

  • #4
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    92
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Quote Originally Posted by johnmerlino View Post
    Why would you need to call the function (singularize() and then call the function again (component.singularize()?
    component.singularize() is not a function until
    the function singularize() has ran
    they are not the same thing at all

  • #5
    Regular Coder
    Join Date
    Oct 2009
    Posts
    189
    Thanks
    38
    Thanked 3 Times in 3 Posts
    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.
    Last edited by johnmerlino; 09-18-2010 at 05:28 PM.

  • #6
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    92
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Quote Originally Posted by johnmerlino View Post
    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>

  • #7
    New Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    92
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Code:
    <script>var component = window.location.hash.replace('#', '');		
    		
    		alert("The component name is " + component);		
    			
    				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>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •