Questions tagged «cyclic-dependency»

13
如何处理Node.js中的循环依赖关系
我最近一直在使用nodejs,并且仍然要处理模块系统,因此很抱歉这是一个明显的问题。我想要大致如下的代码: a.js(主文件与节点一起运行) var ClassB = require("./b"); var ClassA = function() { this.thing = new ClassB(); this.property = 5; } var a = new ClassA(); module.exports = a; b.js var a = require("./a"); var ClassB = function() { } ClassB.prototype.doSomethingLater() { util.log(a.property); } module.exports = ClassB; 我的问题似乎是我无法从ClassB实例中访问ClassA实例。 有没有正确/更好的方法来构造模块来实现我想要的?是否有更好的方式在模块之间共享变量?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.