MVC allows for a clean an testable separation between the behavior (controller) and the view (HTML template). A Controller is just a JavaScript class which is grafted onto the scope of the view. This makes it very easy for the controller and the view to share the model.
The model is simply the controller's this. This makes it very easy to test the controller in isolation since one can simply instantiate the controller and test without a view, because there is no connection between the controller and the view.
setUrl()
and readUrl()
functions copy the game state to/from the URL's
hash so the browser's back button will undo game steps. See deep-linking. This example calls $watch()
to set up a listener that invokes readUrl()
when needed.