O'Reilly logo

Mastering KnockoutJS by Timothy Moran

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

Binding to plain JavaScript objects

The last part of Durandal that we are going to cover is the observable plugin, which allows data binding to use normal viewmodel properties as observable objects by converting them under the hood.

The observable plugin uses JavaScript getters and setters created with defineProperty, which is part of the ECMAScript 5 specification. Only modern browsers support this feature, so if your application needs to work in Internet Explorer 8, the observable plugin will not work.

Using the observable plugin removes one of the most common complaints from Knockout's syntax: the parentheses. All of the property access is executed using plain syntax, whether reading or assigning values:

function Contact() { var self = this; self.firstName ...

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