【问题标题】:is the bidirectional reference will cause the peformance issue?双向参考会导致性能问题吗?
【发布时间】:2011-12-12 13:04:29
【问题描述】:

在我的项目中,我在做UI相关操作时使用了mvc的概念。

例如,有一个名为“Map”的模型,那么除了“Map”对象之外,还有另一个对象“MapView”。

现在我以这种方式创建它们:

function Map(){
  //other codes.
  this.view=new MapView(this);
}


function MapView(model){
  //other code
  this.model=model;
}

现在模型和视图都相互引用了。

我想知道这是最佳做法吗?

这会导致性能问题吗?

【问题讨论】:

  • 你的模型和你的视图不应该相互引用,这取决于你如何实现 MVC,你的控制器应该处理这个问题。 take a look at this answer

标签: javascript model-view-controller


【解决方案1】:

在性能方面没有任何问题(但在 IE3 或 NN4 上可能会变慢)。

但是从设计的角度来看,双向引用似乎很糟糕。

您可能希望使用引用传递,例如 MapView.render(model)

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 2015-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2012-11-12
    相关资源
    最近更新 更多