title: JS prototype (this) "dot" function without native Object
body: <p><strong>I'd like to know how to make the second script return same value as the first one (by modifying MyObject), so I don't have to extend native objects.</strong></p>
  
  <p>Basically, I want to be able to call the function as parameter.functionName() instead of functionName(parameter).</p>
  
  <pre><code>Object.prototype.arraySum = function()
  {
    var sum = 0;
  
    for(var i = 0; i &lt; this.length; i++)
    {
      sum += this[i];
    }
  
    return sum;
  }
  
  console.log([1,2,3,4].arraySum()); /* return: 10 */
  </code></pre>
  
  <hr>
  
  <pre><code>function MyObject()
  {}
  
  MyObject.prototype.arraySum = function()
  {
    var sum = 0;
  
    for(var i = 0; i &lt; this.length; i++)
    {
      sum += this[i];
    }
  
    return sum;
  }
  
  console.log([1,2,3,4].arraySum()); /* return: [1,2,3,4].arraySum is not a function */
  </code></pre>
  
  <p>I've looked through many questions here, but I haven't found the answer.</p>