“Hello World” in MVC Pattern

var M = {}, V = {}, C = {};

M.data = "hello world";

V.render = function (M) { alert(M.data); }

C.handleOnload = function () { V.render(M); }

window.onload = C.handleOnLoad;

Controller (C) listens on some kind of interaction/event stream. In this case it’s the page’s loading event.

Model (M) is an abstraction of a data source.

View (V) knows how to render data from the Model.

The Controller tells to View to do something with something from the Model.

In this example

  • the View knows nothing about the Model apart from it implements some interface
  • the Model knows nothing of the View and the Controller
  • the Controller knows about both the Model and the View and tells the View to go do something with the data from the Model.

Note the above example is a severe simplification for demonstrating purposes. For real “hello world” examples in the JS MVC world go take a look at todoMVC

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)