Coding differences between API 1.6 and 3.6

3325
5
09-25-2013 04:39 AM
JoseSanchez
Occasional Contributor III
Hi all

In API 1.6 the javascript source code started with:

<script type="text/javascript">
      dojo.require("esri.map");

      var myMap, myTiledMapServiceLayer;
      function init() {
    



Now in version 3.6 I see that the same code stars in a different way, with a require that covers the whole script. Why?

I find the 1.6 way easier to read.

<script src="http://js.arcgis.com/3.6/"></script>
    <script>
      var map;
      require([
        "esri/map", "esri/layers/FeatureLayer", 
        "esri/tasks/query", "esri/tasks/QueryTask", 
        "esri/tasks/GeometryService", "esri/tasks/BufferParameters",
        "esri/graphic", "esri/InfoTemplate", "esri/symbols/SimpleMarkerSymbol",
        "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol", 
        "esri/config", "dojo/_base/Color", "dojo/dom", "dojo/domReady"
      ], function(
0 Kudos
5 Replies
AndyBurns
Occasional Contributor
ESRI is moving the core dojo towards AMD following dojo's move towards it earlier.

https://developers.arcgis.com/en/javascript/jshelp/inside_dojo_amd.html

Legacy syntax is still supported with dojo but its best to get onboard with AMD as it will be the future.
0 Kudos
KenBuja
MVP Esteemed Contributor
You should also take a look at this tutorial to get a better understanding of the new coding concepts.

While some of the changes are fundamental and at first glance might be  confusing, they are all there for good reasons to make your code be more  efficient, run faster, better leverage JavaScript and make your code  more maintainable.
0 Kudos
JonathanUihlein
Esri Regular Contributor
Hi jsn,

This link should help explain the whys and hows of using AMD.

http://dojotoolkit.org/blog/learn-more-about-amd

*edit

I noticed you were looking for older samples in another thread and felt my response should have probably been posted in this thread.

Hey jsn,

It's a great time to start learning and using AMD syntax because DOJO 2.0 will soon be released and the legacy syntax will no longer be supported in newer versions of the API.

I think AMD style ends up making the code much more clean and readable from a programmer's perspective (not to mention, faster apps!)

I noticed that you are using version 1.6 of the JSAPI, from the other thread. That version was released in February 2010. Since then, many improvements and features have been added. You should check them out! They are fantastic.
0 Kudos
JoseSanchez
Occasional Contributor III
Thank you all!!
0 Kudos
zhongrenGu
New Contributor III

in browser, if we use dojo, wo can go faster,AMD:just like  we can do more things..thanks

0 Kudos