Reference viewer created in separate script

1. A concise explanation of the problem you're experiencing.

This is likely my not understanding javascript very well, but I can't figure out how to reference a viewer instance that was created and returned from a separate script. What I would like to do is have an initialization script that creates a viewer and a few methods. One method would be to add a satellite. Then in a separate script be able to toggle on / off the visibility of any entities in that viewer. I can't seem to be able to reference that viewer or the entities added to it from another script.

After calling the app.initCesium() method below, I thought I should be able to reference the viewer via app.viewer, but that doesn't work. Any help or further reading would be appreciated. Thanks in advance.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

var app = (function () {
    var _viewer = {};
    var _initCesium = function () {
        _viewer = new Cesium.Viewer('cesiumContainer',
);
    };
// Exercise #1
    var _addSatellite = function () {
    var stopDate = \('\#startDate'\)\[0\]\.valueAsDate;     stopDate\.setDate\(stopDate\.getDate\(\) \+ 1\);     // create json post data for the service         var postData = \{         Start: ('#startDate').val() + "T00:00:00Z",
        Stop: stopDate.toISOString(),
        SSC: \('\#sscNumber'\)\.val\(\),         PathColor: ('#pathColor').val(),
        SatelliteName: \('\#sscNumber'\)\.val\(\),         OutputSettings: \{           Step: "900",           TimeFormat: "Epoch",           CoordinateFormat:\{             Coord: "XYZ",             Frame: "Inertial"           \}         \}       \};     // call STK Analytical Services \(using jQuery ajax call\)         .ajax({
      url: "https://saas.agi.com/V1/vehiclePath/czml/sgp4?u=RPC3D3vVaFogiwFO",
      type: "POST",
      data: postData,
      success: function (result,status){
        addCzmlDataSource(result);
      },
      error: function(error){
        alert(error.responseText);
      }
    });
    };

    return {
        initCesium: _initCesium,
        addSatellite: _addSatellite,
        viewer: _viewer
        
    };

})();

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

4. The Cesium version you're using, your operating system and browser.

Hi there,

Like you said this is a JavaScript question, not quite a Cesium question. You’ll have better luck asking in a more general coding forum, it looks like a scoping issue to me.