如何在另一个js文件中使用其他js文件的变量或function,在客户端是不支持的。
导出//a.jsvar a = 10;module.exports = a;
导入//b.jsvar a = require("./a.js");console.log(a);
1-1
导出//a.jsvar a = 10;function show(){console.log("show")}module.exports = {a,show}
导入//b.jsconst obj = require("./a.js");console.log(obj)Tips:一个文件中只能有一个module.exportsmodule.exports == exports
1-2 exports导出 不推荐
Tips:不支持字面量的形式
var a = 10;function show(){console.log("show")}/* exports */console.log(module.exports == exports)/* 不推荐 */exports.a = a;exports.show = show;
