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>
// index.js function onPress() { var p = document.getElementById('hello'); p.innerHTML = 'Hello bestswifter'; }
The