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!
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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