Evented Models

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 ...

Get Async JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.