前端require代码抽离小技巧
作者:互联网
DEMO
文件目录结构
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
标签:exports,plugin,require,抽离,js,module,test,前端 来源: https://www.cnblogs.com/guangzan/p/11224503.html