0

In my project,I use the mvc concept when do the UI related operation.

For example,there is a model named "Map",then there is another object "MapView" along with "Map" object.

Now I create them this way:

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


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

Now both the model and view have a reference to each other.

I wonder this is the best practice?

Will this cause performance problem?

hguser
  • 35,079
  • 54
  • 159
  • 293
  • your model and your view should not have reference to eachother, depending on how you implement the MVC, your controller should be taking care of this. [take a look at this answer](http://stackoverflow.com/questions/7621832/architecture-more-suitable-for-web-apps-than-mvc/7622038#7622038) – rlemon Dec 12 '11 at 13:08

1 Answers1

0

There is nothing wrong performance wise (it might slow down on IE3 or NN4 though).

However it seems bad to have a bidirectional reference from a design view point.

You may want to use reference passing instead like MapView.render(model)

Raynos
  • 166,823
  • 56
  • 351
  • 396