O'Reilly logo

Backbone.js Cookbook by Vadim Mirgorod

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

Overriding getters and setters

Sometimes it is required to override getters or setters in your application. There can be different reasons to do so:

  • An attribute is stored in a different format rather than a format for input or output
  • You have a virtual attribute that is not stored in the model, but depends on other attributes
  • Prevent illegal values to be assigned to an attribute

By default, Backbone does not allow users to override getters or setters, but there is an extension named Backbone.Mutators, which allows you to do so.

Getting ready

There is a link to download Backbone.Mutators from the GitHub page https://github.com/asciidisco/Backbone.Mutators.

To include this extension into your project, save the backbone.mutators.js file into the lib folder ...

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