title: javascript - type cast of Custom object
body: <p>I have 2 custom classes:</p>
  
  <p>//first class</p>
  
  <pre><code>var MyPoint = function(x, y, size) {
  
      this.x = x;
      this.y = y;
      this.size = size;
  };
  
  MyPoint.prototype.paint = function(ctx) {
      //do some drawing in here
  }
  </code></pre>
  
  <p>//second class</p>
  
  <pre><code>var MyPath = function(a, b, c) {
  
      this.myPoints = new Array(); //array of the MyPoint objects
      this.size = 0;  //the size of the myPoints array
  };
  
  //add function add an object of MyPoint to the myPoints array
  MyPath.prototype.add = function(mp) {
     index = 0;
     id (size &gt; 0) {
         index = size -1;
      }
     this.myPoints[index] = mp;
     size++;
  }
  
  MyPath.prototype.paint = function(ctx) {
  
      for(I = 0; I &lt; this.size; I++ {
          this.myPoints[I].paint(ctx);  //this is where my problem is
      }
  }
  </code></pre>
  
  <p>The problem I am facing is the last line.  When I ran this code, the error was that the paint method was undefined.  When I tried to cast the array element at the ith position to MyPoint using ((MyPoint)this.myPoints[I].paint(ctx),
  I got the syntax error.  How do I type cast properly?</p>