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. #2
    Senior Coder
    Join Date
    Aug 2010
    Posts
    1,105
    Thanks
    30
    Thanked 242 Times in 240 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
  •