Book Image

Mastering ArcGIS Server Development with JavaScript

By : Raymond Kenneth Doman
Book Image

Mastering ArcGIS Server Development with JavaScript

By: Raymond Kenneth Doman

Overview of this book

Table of Contents (18 chapters)
Mastering ArcGIS Server Development with JavaScript
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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() * 10) + 1);
  return {
    guess: function (num) {
      if (num === mysteryNumber) {
        alert("You guessed the mystery number!");
      } else if (num < mysteryNumber) {
        alert("Guess higher.");
      } else {
        alert("Guess lower...