Home > Web Front-end > JS Tutorial > A brief introduction to JavaScript modularity

A brief introduction to JavaScript modularity

阿神
Release: 2017-02-03 17:48:01
Original
1283 people have browsed it

Preface

Regarding modularization, the most direct manifestation is the require and import keywords we wrote. If If you look up relevant information, you will definitely encounter terms such as CommonJS and CMD AMD, as well as unfamiliar frameworks such as RequireJS and SeaJS. For example, the official website of SeaJS describes itself this way: "Simple and friendly module definition specification, Sea.js follows the CMD specification. Natural and intuitive code organization, automatic loading of dependencies..."

As a front-end novice, I am honest He looked confused and couldn't understand. According to my usual style, before introducing something, I always have to explain why it is needed.


JavaScript Basics

Students who are working on the client are familiar with OC You should be familiar with #import "classname", Swift's Module and file modifiers, and Java's import package+class mode. We are accustomed to the pattern that referencing a file refers to a class. However, in a dynamic language like JavaScript, things have changed. For example:

<html>
  <head>
    <script type="text/javascript" src="index.js"></script>
  </head>

  <body>
    <p id="hello"> Hello Wrold </p>
    <input type="button" onclick="onPress()" value="Click me" />
  </body>
 </html>
Copy after login
// index.js
function onPress() {
    var p = document.getElementById(&#39;hello&#39;);
    p.innerHTML = &#39;Hello bestswifter&#39;;
}
Copy after login

The

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template