O'Reilly logo

Async JavaScript by Trevor Burnham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required