Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying all the properties in Backbone.Model

I'm using Backbone in a mobile project. Let's say I've a sample class like this.

var Person = Backbone.extend({

});

The Person class the following properties firstName, lastName, age and gender. I want to specify all these properties in the class. So other developers know what are the properties they've to set for the instance. After going through the documentation I see there is a property called defaults which I could use.

var Person = Backbone.extend({
   defaults: {
      firstName: '',
      lastName: '',
      age: null,
      gender: null
   }
});

But I see the purpose of defaults property is different right? Not to let people know what are the properties the class contains. Is there any better way I can achieve this?

like image 459
VJAI Avatar asked Oct 31 '22 15:10

VJAI


1 Answers

In our project we use defaults for this purpose. It solves the problem quite well, and may also serve as a documentation point. There's no other backbony-way of doing this which I know of. However, you can still use the old-fashioned comments :)

like image 94
Dethariel Avatar answered Nov 08 '22 04:11

Dethariel