November 2012
Intermediate to advanced
106 pages
2h 20m
English
When an object has a PubSub interface, we call it an evented object. A special case is when an object used to store data (a model) publishes events whenever its contents are modified. Models are the M in Model-View-Controller (MVC), which has become one of the hottest topics in JavaScript programming in the last few years. The core concept is that MVC applications are data-centric so that model events impact the DOM (aka the View) and the server (via the Controller).
Let’s look at the hugely popular Backbone.js framework.[29] You create a new model like so:
| | style = new Backbone.Model( |
| | {font: 'Georgia'} |
| | ); |
model just represents the simple object that was passed in.
| | style.toJSON() // {"font": "Georgia"} |
But unlike ...