module.export = {
tt: function(){
Console.log ("This is a function, that is, an object")
}
}
var obj = require('../tt.js')
Obj.t () // "This is a function, that is, an object"
Module's export property of the object, accessing this property through the Require method in other files
Export default {// (This method is the most common way, join the default key "You can use any variable name when IMPORT and does not need to mark {})
b: function(){
Console.log ("This is a function")
}
}
Import {a as aa, b, c} // AS keyword other usage
Import is used to receive Export Deault
Article directory The difference between `require` and `import` origin Export command / import command CommonJS es6 Static optimization requirewithimportDifference origin Before the birth of es6, js h...
The difference between require and import Before es6, js has not had its own module syntax. In order to solve this problem, there is a requirement for require.js. After the release of es6, js introduc...
Foreword Some time ago wrote an articleimport and require Depth - depth from shallow thinking to bring NodeThe articles comeimportis based onrequireImplementation, and implementation is different in d...
Before ES6, there was a bill to load JS modules, the most important being CommonJS and AMD specifications. The former CommonJS is mainly used in servers to achieve synchronous loading, such as nodejs....
When the front-end application becomes more and more complex, we want to divide the code into different modules for easy reuse and on-demand loading. Require and import are statements that introduce m...
First we have to understand the basic syntax of Require and Import: REQUIRE's basic syntax: Define module.export in the exported file, the type of object to export is not limited (which can be any typ...
Should I use require or import? The use of require is very simple, it is equivalent to the portal of module.exports, what is behind module.exports, what is the result of require, objects, numbers, str...
Both require and import are used for js modularization. First, require Require is the specification of commonjs. The node application is composed of modules and complies with the specification of comm...
Require/exports appears first. It is produced in the specifications drafted by the developers of the js community and is widely recognized or widely used. Import/export is ES6. CommonJS is a specifica...
import is a reference require a copy In theory, the value of reference require changes will no longer be referenced files inside the affected, and this indeed is the case, That way the value of...