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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    60
    Thanks
    65
    Thanked 0 Times in 0 Posts

    Javascript Extension Method how do I make one??

    How do I make my own custom extention method like .replace("-","");

    so for example:




    Code:
    function removeEs(text){
    
    return text.replace("e","");
    }
    
    
    var s ="hello world";
    
    var d = s.removeEs();
    //d is now "hllo world"

    Thanks

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    String.prototype.removeEs = function (){

    return this.replace("e","");
    }


    var s ="hello world";

    alert(s.removeEs());


    http://www.w3schools.com/jsref/jsref...ype_string.asp


  •  

    Posting Permissions

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