commonJS
module.exports={
title:"标题",
cityName:"hangzhou",
city:"杭州"
}
const config = require("./config.js")
module.exports=function(params){
let keys = Object.keys(config)
console.log(keys)
for (let v of params) {
console.log(v);
};
}
const fun = require("./fun.js")
fun(['a','b','c'])
exports 和 module.exports
---------------------------
exports.log =function (str) {
console.log(str);
}
var a = require("./a");
a.log("bbbb");
---------------------------
function func1(val){
console.log(val)
}
function func2(val){
console.log(val)
}
module.exports = {
func1,
func2
}
var a = require("./a");
a.func1(1);
a.func2(2);
export 和 export default
export function fun1(){}
import { fun1 } from 'a.js'
export default function fun2(){}
import fun2 from 'b.js'