Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是学习道场的新手,我遇到了require()和define()功能,但我无法理解其中任何一个。另外,我什么时候使用它们中的任何一个?一个小的演示或示例将是有益的。非常感谢!
require()
define()
require并且define是异步模块定义 (AMD) API 的一部分。
require
define
你define用来定义一个可以被其他代码使用的模块。一般define会在一个javascript文件中使用。javascript 文件正在定义一个模块。所有 Dojo 文件都使用定义。
当您不定义模块时使用require,但您需要已定义的模块。一般require会在 HTML 页面中使用。HTML 页面不是模块,但需要模块才能将页面呈现给用户。
AMD API
https://github.com/amdjs/amdjs-api/wiki/AMD