Q:

what is happening in following code

Could any one tell me what is happening in following code? I'm trying to work through a tutorial and I'm getting a bit lost.
I'm not sure how the following function could be called, or how to set the parameters (e.g. if brng =45 and dist=1.
LatLon.prototype.destinationPoint = function(brng, dist) {

    dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist :  NaN;

    dist = dist/this._radius;  // convert dist to angular distance in radians

    brng = brng.toRad();  // 

    var lat1 = this._lat.toRad(), lon1 = this._lon.toRad();

    var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + 
                            Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) );

    var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1),  
                                   Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2));

    lon2 = (lon2+3*Math.PI)%(2*Math.PI) - Math.PI;  // normalise to -180...+180

    return new LatLon(lat2.toDeg(), lon2.toDeg());

}

This code can be found at following page http://www.movable-type.co.uk/scripts/latlong.html 

A:

don't know if you ever before coded JS but you have to create a function which will represent you class...
function LatLon(lat, lon, rad) {

if you wrote this you can invoke this "constructor" by typing
var myLatLon = new LatLon(lat, lon, rad)

plus the same from before! 

