I have the following model:
var User = Backbone.Model.extend({
defaults: {
status: this.constructor.status.OFFLINE,
},
},
{
status: {
OFFLINE: 0,
ONLINE: 1,
BUSY: 2,
AWAY: 3,
},
}
);
I also tried:
status: User.status.OFFLINE
but I keep getting this error:
TypeError: 'undefined' is not an object (evaluating 'this.constructor.status.OFFLINE')
or this:
TypeError: 'undefined' is not an object (evaluating 'User.status')
Any help? Thanks
You are trying to reference a static property that is not defined at the moment you create your User model.
Either define your defaults as a function
http://jsfiddle.net/nikoshr/6XuC8/
or define first your static properties and then extend User.prototype to add your defaults:
http://jsfiddle.net/nikoshr/6XuC8/2/