Book Image

Backbone.js Essentials

By : Jeremy Walker
Book Image

Backbone.js Essentials

By: Jeremy Walker

Overview of this book

<p>This book offers insight into creating and maintaining dynamic Backbone.js web applications. It delves into the the fundamentals of Backbone.js and helps you achieve mastery of the Backbone library.</p> <p>Starting with Models and Collections, you'll learn how to simplify client-side data management and easily transmit data to and from your server. Next, you'll learn to use Views and Routers to facilitate DOM manipulation and URL control so that your visitors can navigate your entire site without ever leaving the first HTML page. Finally, you'll learn how to combine those building blocks with other tools to achieve high-performance, testable, and maintainable web applications.</p>
Table of Contents (20 chapters)
Backbone.js Essentials
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Overriding a class constructor


Whenever a Backbone class is instantiated, it runs the code defined in its initialize method. However, this code isn't run until after the new object has been instantiated. This means that even if you define an initialize method for a Model class, the attributes of that Model class will already have been set before your initialize code is even called.

Normally, this is a good thing, as it is convenient to have things like the attributes of the Model class already set, but sometimes, we want to take control before this happens. For example, let's reimagine our previous scenario of fiction and nonfiction books, only this time instead of having a single Collection class that can create both types of books, we want a Collection that only creates one type and we want this type decided by the first book that we give the Collection class when its instantiated.

In other words, if the first book given to our Collection class has the isFiction property, we want our Collection...