title: Uncaught TypeError: Property 'dist2' of object [object Object] is not a function
body: <p>I have this functions that should return me the distance from point p to segment line v-w.
  The problem i have is after some time i receive the following error:
  Uncaught TypeError: Property 'dist2' of object [object Object] is not a function.</p>
  
  <p>I receive it in distToSegmentSquared directly,not even calling the function dist2().Is it any other dist2() anywhere in jquery?I found none.</p>
  
  <p>Code:</p>
  
  <pre><code>function sqr(x) {
      return x * x;
  }
  
  function dist2(v, w) {
      console.log(v);
      console.log(w);
      return sqr(v.x - w.x) + sqr(v.y - w.y);
  }
  
  function distToSegmentSquared(p, v, w) {
      var l2 = dist2(v, w);
      if (l2 == 0)
          return dist2(p, v);
      var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
      if (t &lt; 0)
          return dist2(p, v);
      if (t &gt; 1)
          return dist2(p, w);
      return dist2(p, {x: v.x + t * (w.x - v.x),
          y: v.y + t * (w.y - v.y)});
  }
  
  function distToSegment(p, v, w) {
      return Math.sqrt(distToSegmentSquared(p, v, w));
  }
  </code></pre>
  
  <p>The values that are given in for that error are:</p>
  
  <pre><code>p: Object
  x: 461
  y: 333
  
  v: Object
  x: 80
  y: 120
  
  w: Object
  x: 260
  y: 120
  </code></pre>