前端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
转载于:https://www.cnblogs.com/guangzan/p/11224503.html
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除
上一篇:异常简介转载 下一篇:将PCM格式存储成WAV格式文件转载