title: Should i modify the prototype of String?
body: <p>I was about to create a trim function in javascript, but as i don't want to reinvent the wheel i googled for this method.<br>
  I found this link 
  <a href="http://www.somacon.com/p355.php" rel="noreferrer">http://www.somacon.com/p355.php</a>  </p>
  
  <p>The Solution it provided is:</p>
  
  <pre><code>String.prototype.trim = function() {
      return this.replace(/^\s+|\s+$/g,"");
  }
  String.prototype.ltrim = function() {
      return this.replace(/^\s+/,"");
  }
  String.prototype.rtrim = function() {
      return this.replace(/\s+$/,"");
  }
  </code></pre>
  
  <p>also it says if you don'y wnt to change the prototype of String then use this:</p>
  
  <pre><code>function trim(stringToTrim) {
      return stringToTrim.replace(/^\s+|\s+$/g,"");
  }
  function ltrim(stringToTrim) {
      return stringToTrim.replace(/^\s+/,"");
  }
  function rtrim(stringToTrim) {
      return stringToTrim.replace(/\s+$/,"");
  }
  </code></pre>
  
  <p>I would like to know in  what scenario one should <strong>not</strong> modify the prototype of String or say any object.</p>