Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the main difference between require() and define() function in dojo and when would we use either?

I am new to learning dojo and I have come across the require() and define() functions and I can not get my head around either of them. Also, when would I use either of them? A small demo or example would be beneficial. Many Thanks!

like image 704
Simple-Solution Avatar asked Jul 19 '12 10:07

Simple-Solution


People also ask

What is the difference between require and define?

require() and define() both used to load dependencies. There is a major difference between these two method. Require(): Method is used to run immediate functionalities. define(): Method is used to define modules for use in multiple locations(reuse).

What is Dojo package?

A JavaScript toolkit that saves you time and scales with your development process. Provides everything you need to build a Web app. Language utilities, UI components, and more, all in one place, designed to work together perfectly. Get Dojo.


1 Answers

require and define are part of the asynchronous module definition (AMD) API.

You use define to define a module that can be consumed by other code. Generally, define will be used in a javascript file. The javascript file is defining a module. All Dojo files use define.

You use require when you are not defining a module, but you require modules that have been defined. Generally, require will be used in HTML pages. The HTML page is not a module, but requires modules to present the page to the user.

AMD API

https://github.com/amdjs/amdjs-api/wiki/AMD

like image 75
Craig Swing Avatar answered Oct 02 '22 15:10

Craig Swing