DEMO

文件目录结构
使用 require 的一个技巧

plugin.js

// /CommonJS规范
// var exports = module.exports;
exports.test = function () {
    console.log("This is a plugin");
}

req1.js

const plugin = require("./plugin");

require("./req2")(plugin); // 等于是执行module.exports

req2.js

module.exports = plugin => {
    // Do something with plugin
    plugin.test();
}

运行req1.js
使用 require 的一个技巧

相关文章:

  • 2021-08-10
  • 2021-09-04
  • 2022-01-21
  • 2021-04-22
  • 2021-11-21
  • 2021-07-07
  • 2021-08-31
  • 2022-02-15
猜你喜欢
  • 2021-08-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2021-06-24
相关资源
相似解决方案