buffering in JavaScript with app.tb

841
1
09-19-2014 07:16 AM
BruceRalston
New Contributor II

I have noticed that some examples of buffering in javascript api do not use and app.tb, app.gsvc, or app.map.  The Buffer a Point sample is an example.  However, the new dojo style samples, like util_buffergraphic do use a structure like

app = {

      map: map,

      tb: tb,

      gsvc: gsvc

    };

I assume this is required by the newer dojo style.  Is this correct?  Is there somewhere I can read up about why this is necessary in the new style dojo but not in the old style dojo?

Thanks,

0 Kudos
1 Reply
BruceRalston
New Contributor II

I have figured out what is going on .  The object defined at the end of the Buffer any shape | ArcGIS API for JavaScript has automatic global scope (a JavaScript term).  That means it is known throughout the application (similar to HTML global scope), so inline scripts outside the main script tag have access to the app objects contents.

The confusion arises because the example at Geodesic buffering | ArcGIS API for JavaScript  declares app as follows

var app = {}

This gives this variable JavaScript global (not automatic global) scope. This means that its contents are NOT available outside the script environment (outside the <script> and </script> tags).  Since there are no scripts outside main script block, there is no harm. However, if you enter the var app = {} line in the Buffer any shape example, it will fail.  Also,

if you remove the app from the Geodesic buffering sample (using only map, gsvc) that sample still works fine.

0 Kudos