Require

859
4
Jump to solution
02-07-2014 05:09 AM
jaykapalczynski
Frequent Contributor
Looking at examples and seeing two different ways to require dojo.
Whats the difference and which one should I be using?
Sorry for the green question...

dojo.require("esri.map"); dojo.require("esri.layers.FeatureLayer")


Or like this

var map;   require([     "esri/map", "esri/layers/FeatureLayer"   ], function(   Map, FeatureLayer   ) 
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
The second way (AMD) is the direction that Dojo and Esri's JSAPI are going. The first way (legacy) will eventually be deprecated when Dojo 2.0 is realeased. Take a look at this help page.

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor
The second way (AMD) is the direction that Dojo and Esri's JSAPI are going. The first way (legacy) will eventually be deprecated when Dojo 2.0 is realeased. Take a look at this help page.
0 Kudos
jaykapalczynski
Frequent Contributor
Thank you...Cheers
0 Kudos
ThomasGagne
New Contributor II
I'm missing something.

Imagine I have another script on the page that needs to call a function inside the require().  None of the functions inside require() are visible outside of it.

For instance, let's say I already have the point or x,y and simply want to map it.  If the code with the xys is outside the require(), how can I get the points mapped?
0 Kudos
ReneRubalcava
Frequent Contributor
You would create separate modules to keep your code modular.
Here's a diagram I have been using to kind of explain how require/define work together a little easier for people.
[ATTACH=CONFIG]31596[/ATTACH]

So you could have a module that somehow produces your coordinates, and can return them via a pattern like the revealing module pattern in the module.


You can then call the module from your the methods inside the require() of your application.

Every Dojo app needs at least one require() method, but can have multiple modules using define().

Some good refs.
http://dojotoolkit.org/documentation/
http://dojotoolkit.org/documentation/tutorials/1.9/modules/
0 Kudos