1.1

1.2 直接导出

  1. //http.js
  2. function http(){
  3. console.log("http请求")
  4. }
  5. module.exports
  1. //b.js
  2. var http = require('./http');
  3. http();

1.3 解构导入

  1. function http(){
  2. console.log("http12")
  3. }
  4. module.exports = {
  5. http
  6. }
  7. //a.js
  1. var {http} = require('./a');
  2. http()
  3. //b.js