JavaScript Learn how to use-require

Source: Internet
Author: User

When the JS code needs to invoke other JS file methods, it is necessary to use require to introduce other JS files

Cases:

1. Create a new Test.js file on the desktop

CD Desktop

Touch Test.js

2. Enter the JS file

Vim Test.js

3. Input "I" to edit the JS file

For example, enter content:

var a = 12;

Console.log (a);

var subject = CustomFormat ("Now has%s apples" + a),//customformat is a method in Customformat.js, so to introduce the file

4, so to introduce the file in Test.js

If the customformat.js and Test.js directories are the same, for example in this example: CustomFormat. js and Test.js are all on the desktop

So with the path, you can introduce

CustomFormat = require ('./customformat '). CustomFormat;

5, OK, now you can use CustomFormat

6, Beginner JS, there are many do not know the place, one record, Memo.

JavaScript Learn how to use-require

Related Article

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.