This article describes the usage of use function in SeaJS. Share it for your reference, as follows:
With the implementation of module definition specifications such as define, we can develop many modules. But having a bunch of modules doesn't work, we have to make them run. In SeaJS, it is very easy to start the module system:
<script src="path/to/"></script> <script> ('./main'); </script>
Used to load modules in pages. Through the use method, any module can be loaded in the page.
grammar: (id, callback?)
// Load the module main and execute the specified callback when the load is completed('./main', function(main) { (); });
The use method can also load multiple modules at once:
// Concurrently load module a and module b, and when both loading is completed, execute the specified callback(['./a', './b'], function(a, b) { (); (); });
The callback parameter is optional. When only one module is loaded and no callback is required, you can usedata-mainProperties to simplify:
<script src="path/to/" data-main="./main"></script>
The above code is equivalent to:
<script src="path/to/"></script> <script> ('./main'); </script>
SeaJS also providesdata-config To load the configuration file:
<script src="path/to/" data-config="path/to/config"></script>
data-config equivalent:
({ preload: ['path/to/config'] });
Path resolution rules andConsistent.
What I use here is:
<script src="/js/lib/" data-config="/js/"></script> <script> ('/js/main', function(main) { main.banner_focus('#focus'); });
Note:main is the module name.Functions defined for modules can pass parameters over.
For more information about JavaScript, readers who are interested in reading this site's special topic:JavaScript extension skills summary》、《Summary of JavaScript characters and string operation techniques》、《Summary of JavaScript mathematical operations usage》、《Summary of json operation skills in JavaScript》、《Summary of JavaScript Errors and Debugging Skills"and"Summary of JavaScript data structure and algorithm techniques》
I hope this article will be helpful to everyone's JavaScript programming.