COMMONJS Module Specification

Source: Internet
Author: User

1. What is Modular

File scope

Communication rules

Load require

Export exports

2, COMMONJS module specification

JavaScript in node also has a very important concept: module concept

Module scope

Use the Require method to load a module

Syntax: var custom variable name = require (' module ')

Two functions:

Executing the code in the loaded module

Get the exports export interface object in the loaded module

Use the exports excuse object to export members in a module

The module scope in node, in which all members of the default file are valid in the current file module

For members who wish to be accessed by other modules, we need to attach these exposed members to the object of the exports interface.

Exporting multiple members must be in the object

Module.exports = {

Key: Value,

..........

} or module.exports.xxx = xxx;

Export a single member must be module.exports.xxx = XXX;

Note: Module.exports = = = Exports

(Supplementary one humorous: 301 Status Code Permanent orientation, browser will remember, 302 status code temporary redirect)

COMMONJS Module Specification

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.