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?
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With