5

It seems to me like this:

var point;
require(['esri/geometry/Point'], function(Point) {
    point = new Point();
}

does the same thing as:

var point = new esri.geometry.Point();

Is there any reason to opt for AMD-loaded constructors?

1 Answer 1

9

They are functionally equivalent. The difference is that require() loads modules using AMD while your second example uses a class from a global variable populated by Dojo's module loader in legacy mode. Technically, you should have to use dojo.require("esri.geomtry.Point") for your second example to work but because the module that defines that class is included in the built version of the API we (Esri) provide, and it's made available via the global esri object, your code will work.

The recommended approach is to use require(). When Dojo goes to 2.0, the legacy loader will be removed and the only way load modules will be require(). Once the esri js api is using Dojo 2.0, there will not be a global esri object by default so all code referencing classes from that global will break.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.