How to call the module of seaJs learning notes

Source: Internet
Author: User
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
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.