doerr@usgs.gov

avoid using a global variable

Discussion created by doerr@usgs.gov on Apr 18, 2012
So I'm creating a graphic on a map that when clicked displays an infowindow.  My infowindow contains radio buttons which I've assigned an onClick function.
Unfortunately, I'm using a global variable to call the widget's function.  How do I avoid using a global variable gShoppingCart?

Here's the pertinent code.

///////////////////////////////////////////////////////////////
// widget
dojo.declare(
  startup: function() {
                        // i define my global here
   gShoppingCart = this;
  },

display_browse_symbols2: function(tileIDassocArray){
                                        var title = 'Title';
     var content = '<input checked="checked" type="radio" name="browseRadioGroup" onClick="gShoppingCart.switchBrowse(\'someurl\')" id="Whatever" value="Whatever" />';

   var attrs = {
    "title": title,
    "content": content
   };

   var orthoTileInfo = new esri.Graphic(point, pms, attrs);

                        this.addGraphic(orthoTileInfo);
},

  switchBrowse: function(browseUrl){
                   // do stuff here when radio button is clicked
  }

);
//////////////////////////////////////////////////////////////////////////////

Outcomes