循环依赖性超级表达式必须为null或函数

时间:2017-08-08 11:21:46

标签: javascript import ecmascript-6 circular-dependency

我们的循环依赖结构应该是合理的。 Light导入Node,导入NodeManager,导入Light。运行我们的代码时,我们得到以下内容

"Super expression must either be null or a function"

节点管理器

// in NodeManager.js
import Light from '../../Light.js'

class NodeManager {
  static _instance;
  static getInstance() {
    if(NodeManager._instance === undefined) {
      NodeManager._instance = new NodeManager();
    }
   return NodeManager._instance;
  }
  ...
  addNode(node){
    ...
    if(node instanceOf Light){
      ...
    }
    ...
  }
}

节点

// in Node.js
import NodeManager from '../../NodeManager.js'
class Node {
  constructor() {
    ...
    NodeManager.instance().addNode(this);
    ...
  }
}

// in Light.js
import Node from '../../Node.js'
class Light extends Node {
  constructor() {
    super();        
    ...
  }
}

出于某种原因,在光中导入Node不起作用,因此Light.js在调用super时会抛出错误。我不确定如何解决这个问题。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

import flask from flask import Flask, session, redirect class Test: def __init__(self, x, y, z): self.x = x self.y = y self.z = z app = Flask(__name__) app.secret_key = 'xyz' @app.route('/') def main(): session['my_object'] = Test(1, 2, 3) return redirect('retrieve') @app.route('/retrieve') def return_my_object(): my_object = session.get('my_object') return str(my_object) if __name__ == '__main__': app.run(debug=True) 必须是您在构造函数中调用的第一件事(请参阅here)。 看起来你在Node类的构造函数中缺少super()调用。