Javascript namespace structure example

$(document).ready(function(){
    flight_app.get_flight('CX-400', function(flight){
        console.log(flight);
    });
    
    //console.log(flight_app.flight_id());
});

var flight_app = function(){
    var fxml_url = 'http://[email protected]/json/FlightXML2/';
    var flight_id = '';


    function get_flight(flight_id, callback){
        var app = this;

        $.ajax({
            type: 'GET',
            url: fxml_url + 'FlightInfoEx', 
            data: { 'ident': flight_id, 'howMany': 1, 'offset': 0 },
            success : function(result) {
                //console.log(result);
                // display some textual details about the flight.
                var flight = result.FlightInfoExResult.flights[0];
                //flight_id = flight.faFlightID;
                //console.log(flight);
                //console.log(get_std_time(flight.filed_departuretime));
                //console.log(get_std_time(flight.estimatedarrivaltime));

                if(typeof callback == 'function'){
                    callback.call(app, flight);
                }
            },
            error: function(data, text) { 
                alert('Failed to fetch flight: ' + data); 
            },
            dataType: 'jsonp',
            jsonp: 'jsonp_callback',
            xhrFields: { withCredentials: true }
        });
    }

    function get_std_time(t){
        var utcSeconds = t;
        var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
        d.setUTCSeconds(utcSeconds);
        return d;
    }

    function get_flight_id(){
        return flight_id;
    }

    return {
        get_flight: get_flight
    }
}();

Reference: