Javascript struct function that takes an argument
<p>Javascript Noob calling for duty!</p>

<p>I would like to write the code for the following:</p>

<pre><code>var p1 = new LatLon(userLat, userLon);                                                    
var p2 = new LatLon(destLat, destLon);  
var dist = p1.distanceTo(p2);    
</code></pre>

<p>which means I need to create a Javascript struct of sorts that will create a position and then also be able to take a second position as an argument. I <strong><em>DO NOT need the code to calculate the distance</em></strong>. I just need to figure out how to create the object and allow it to accept the arguments. Here is my pseudo code/ failed attempt:</p>

<pre><code>function LatLon(userLat, userLon) {
    var pos = {
      'lat': userLat, 'lon': userLon, 'distanceTo': distanceBetweenTwoPos(pos, pos2);
    }
    return pos;
}

function distanceBetweenTwoPos(pos, pos2){
    // here I will do my own calculations. 
}
</code></pre>

<p>Any help on getting something similar to the above, yet functional?</p>
