We have learned how to use seaJs to modularize javascript Functions. It is not enough to modularize javascript. We still need to use this module. So how can we call it outside? Now let's reveal the answer. Today's example will be in the server
We have learned how to use seaJs to modularize javascript Functions. It is not enough to modularize javascript. We still need to use this module. So how can we call it outside? Now let's reveal the answer. Today's example will be run in the server environment, because it depends on js loading.
The define parameter require is the interface of the call module. Through require, we can adjust to this module and to this method. With require, we can easily tune this modular function out. So how can we establish a relationship between the function tab and require? Add "." After require, and then add it to the name of the modular function.
Javascript code that uses require to provide external interfaces
/* Javascript code that uses require to provide external interfaces */define (function (require, exports, module) {function tab () {alert ("this is a modular tab function")} exports. tab = tab;}); tab ();
So how should we call the modular tab function on the page? It is adjusted to the module through the use method in seaJs. This method has two parameters: the first parameter is the module address, and the second parameter is the callback function after the address is loaded successfully. Let's write an address first to see if js can be loaded in.
HTML code 1 called using the use method in seaJs
Menglong xiaozhan