define not specific to RequireJS; it is part of the AMD specification . Burke noted that RequireJS does not implement exactly how AMD points it out, since AMD does not really consider browsers.
define does not have an anonymous function in it. define is a method available for AMD-based JavaScript files to load their data. Libraries such as RequireJS make this available to you. The specific implementation is probably not valuable to you. Therefore, I will consider the one you provided as the most common way to declare a module.
define( [array] , object );
An array is a list of modules that this module depends on. Between modules and files there is from 1 to 1. You cannot have several modules in a file and several files for one module.
An object is a module that you define. It can be anything, a structure, or a function that returns a structure. Read more in the RequireJS docs .
If the object is a function, the arguments passed to the function are the modules listed as dependencies in the first argument of the definition. It is also important to note that when you pass a function as an object , it will only work once. The methods or properties created in this instance may be available at any time, but other modules may be available to them that list this module as a dependency.
Good luck, I recommend playing around with this and reading the docs when something doesn't make sense. RequireJS documents are great for quickly using AMD modules.
Drew Dec 03 2018-11-12T00: 00Z
source share