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

The binding expression parser

The expressions written in data-bind attributes are not truly JavaScript or JSON, though they look very similar. Knockout has its own parser to convert these attributes into JavaScript. Say you write a data-bind attribute like this one:

data-bind="value: name, visible: showName"

Then, the binding provider's job is to return an object like this:

{
  value: function() { return name; },
  visible: function() { return showName; }
}

The default binding provider does this using the ko.expressionRewriting module, which is responsible for calling binding preprocessors and returning a JSON-esque string. Internally, this is done using regex to parse the full attribute into a key/value pair array. This might sound messy, but it gets ...

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