关于require重复加载的问题

来源:3-3 环境 & 调试 ——CommonJS3

Allen_Liu_1106

2017-11-06

代码稍微改了一下,test aa,bb中分别加了一句打印的输出:

test aa.js:

module.exports.test='A';
console.log('now in A');
const modB=require('./test bb');
console.log('modA',modB.test);

module.exports.test='AA';


test bb.js:

module.exports.test='B';
console.log('now in b');
const modA=require('./test aa');
console.log('modB',modA.test);

module.exports.test='BB';

这时候,当bb.js 循环require aa.js的时候,是不是只应该执行aa.js中已经被执行的内容(即 module.exports.test='A';
console.log('now in A');),这样的话,应该打印now in AA才对,但实际上没有打印,求教为啥?

写回答

2回答

Samaritan

2017-11-07

多看一下我们视频的讲解,不要跳过去,实在不行查一下资料,很难两句话说明白

0
1
Allen_Liu_1106
谢谢老师,在commonJS2中就提到过缓存的问题,以后细节要注意!
2017-11-08
共1条回复

Allen_Liu_1106

提问者

2017-11-06

now in A
now in b

now in A             >>>>>>>>>>>>>>>>我认为是不是这里应该有这么一句,求老师指教

modB A
modA BB

0
0

Node.js入门到企业Web开发中的应用

Node.js是Web应用开发的一个福音,特别适合中小型系统的快速开发!

1580 学习 · 303 问题

查看课程