title: Add function in object
body: <p>I try to add function to the object. Why does't it work? The result is undefined. Please help. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;script&gt;
    var calc = function(){
      this.num1 = 5,
      this.num2 = 5,
      compute = function( ) {
        this.result = this.num1 * this.num2;
      }
    };
    
    var myObj =[];
    for(var i=0; i&lt;5; i++){myObj.push(new calc())};
    //calc.compute();
    
     document.write(myObj.compute);
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>