O'Reilly logo

Mastering ArcGIS Server Development with JavaScript by Ken Doman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Defining your widget

With Dojo's AMD style, there are two main ways to use AMD components. Using the require() function plays the script once, and then it's done. But if you want to create a module that can be used over and over again, you would want to define() the module, instead. The define() function creates one or more custom modules to be used by an application.

The define() function takes a single argument, which could be any JavaScript object. Even define("Hello World!") is a valid module definition, though not that useful. You can create more useful ones by passing in objects or object constructors that perform tasks for your application. Review the following example:

define(function () { var mysteryNumber = Math.floor((Math.random() * ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required