We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
有a.js、b.js、c.js三个文件如下,求执行node a.js输出结果
a.js
b.js
c.js
node a.js
a.js代码如下
const b = require('./b.js'); console.log(exports.x); exports.x = 'x'; require('./c.js');
b.js代码如下
const a = require('./a.js'); console.log(a); console.log(a.x); a.x='y';
c.js代码如下
const a = require('./a.js'); console.log(a.x);
输出结果如下
{} undefined y x
CommonJS中的做法是,一旦某个模块被”循环引用“,也就是这个模块没有加载完,就进入了循环,所以原则是,只exports已经执行的那部分,没执行的不输出。
exports
详细原理请阅读阮一峰大佬的JavaScript 模块的循环加载
The text was updated successfully, but these errors were encountered:
No branches or pull requests
题目
a.js
代码如下b.js
代码如下c.js
代码如下输出结果如下
原理
CommonJS中的做法是,一旦某个模块被”循环引用“,也就是这个模块没有加载完,就进入了循环,所以原则是,只
exports
已经执行的那部分,没执行的不输出。详细原理请阅读阮一峰大佬的JavaScript 模块的循环加载
The text was updated successfully, but these errors were encountered: