let fs = require('fs') let req = (moduleName) => { //content表明的是文件內容 let content = fs.readFileSync(moduleName, 'utf8') console.log(content + '\n return module.exports') //最後一個參數是函數的內容體 let fn = new Function('exports','module','require','__dirname','__filename',content + '\n return module.exports') let module = { exports:{} } return fn(module.exports,module,req,__dirname,__dirname) } let msg = req('./a.js') console.log(msg.msg)