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
废话少说,进入主题
下面对上面列举的各点进行举例说明
对于基本数据类型,属于复制。即会被模块缓存。同时,在另一个模块可以对该模块输出的变量重新赋值。
// b.js let count = 1 let plusCount = () => { count++ } setTimeout(() => { console.log('b.js-1', count) }, 1000) module.exports = { count, plusCount } // a.js let mod = require('./b.js') console.log('a.js-1', mod.count) mod.plusCount() console.log('a.js-2', mod.count) setTimeout(() => { mod.count = 3 console.log('a.js-3', mod.count) }, 2000) node a.js a.js-1 1 a.js-2 1 b.js-1 2 // 1秒后 a.js-3 3 // 2秒后
以上代码可以看出,b模块export的count变量,是一个复制行为。在plusCount方法调用之后,a模块中的count不受影响。同时,可以在b模块中更改a模块中的值。如果希望能够同步代码,可以export出去一个getter。
// 其他代码相同 module.exports = { get count () { return count }, plusCount } node a.js a.js-1 1 a.js-2 1 b.js-1 2 // 1秒后 a.js-3 2 // 2秒后, 由于没有定义setter,因此无法对值进行设置。所以还是返回2
The text was updated successfully, but these errors were encountered:
No branches or pull requests
前言
废话少说,进入主题
正文
CommonJS
ES6模块
Example
下面对上面列举的各点进行举例说明
CommonJS
对于基本数据类型,属于复制。即会被模块缓存。同时,在另一个模块可以对该模块输出的变量重新赋值。
以上代码可以看出,b模块export的count变量,是一个复制行为。在plusCount方法调用之后,a模块中的count不受影响。同时,可以在b模块中更改a模块中的值。如果希望能够同步代码,可以export出去一个getter。
The text was updated successfully, but these errors were encountered: