title: React: Where To Extend Object Prototype
body: <p>I created a pure React application using <a href="https://github.com/facebookincubator/create-react-app" rel="noreferrer">create-react-app</a>. I would like to extend the <code>String</code> class and use it in one or more components. For example:</p>
  
  <pre><code>String.prototype.someFunction = function () {
      //some code
  }
  </code></pre>
  
  <p>(You may want to take a look at <a href="https://stackoverflow.com/questions/8392035/javascript-add-method-to-string-class">this question</a> to learn more about extending object prototypes.)</p>
  
  <p>Yes I can define it beside a component and use it within. But what is the best and cleanest way?</p>
  
  <p>Should I write it as a <code>class method</code> or inside <code>componentDidMount</code> or something else?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Is it even "OK" to extend object prototype in React (or in JavaScript) at all?</p>