I do not know how to implement this in javascript, but on c # it would look something like this:
class Program { class View { public Controller Controller { get; set; } public void show() { Console.WriteLine(Controller.Model.Value); } } class Model { public string Value { get; set; } public Model() { Value = "1"; } } class Controller { public View View { get; set; } public Model Model { get; set; } public Controller(View view, Model model) { View = view; Model = model; View.Controller = this; } } static void Main(string[] args) { Controller myController = new Controller(new View(), new Model()); myController.View.show(); myController.Model.Value = "2"; myController.View.show(); Console.ReadLine(); } }
The basic idea is:
Model - contains the data structure.
Controller - Can be played with filling in the data and calling the output of this data to the user interface.
View - contains methods that display the data that was filled in the Model structure by the controller.
Wherein:
Model - knows nothing about how data will be displayed. It is possible that in these classes there is also an implementation for filling and processing data (not only in the controller)
View - knows nothing about where it comes from and how data is processed. He knows only where and how to display this data.
Controller - Knows nothing about data mapping. In principle, you may be completely unaware of how the data is filled and processed (if the logic is transferred to the Model). He knows only that the data is stored in the Model and displayed through the View.