I have a backbone model
var app = app || {};
app.Era = Backbone.Model.extend({
defaults: {
from: Number.NEGATIVE_INFINITY,
until: Number.POSITIVE_INFINITY,
stash: {
from: null,
until: null
},
_enabled: true
},
toggle: function(){
if(this.get('_enabled')){
this.disable();
}else{
this.enable();
}
this.save();
},
enable: function(){
this.from = this.stash.from;
this.until = this.stash.until;
this.stash.from = null; // strictly speaking unnecssary
this.stash.until = null;
this._enabled = true;
},
disable: function(){
this.stash.from = this.from;
this.stash.until = this.until;
this.from = null;
this.until = null;
this._enabled = false;
},
enabled: function(){
return this._enabled;
},
});
which I’m trying to extend like so
Name = app.Era.extend({ defaults: { value: '' } });
This seems to work, I get no error in the console.
I can even instantiate a new Name, but when I try to instantiate a new Name, I get an Error message:
> era = new app.Era()
child
> era.get('from')
-Infinity
> Name = app.Era.extend({ defaults: { value: '' } })
function (){ return parent.apply(this, arguments); }
> name = new Name()
child
> name.get('value')
TypeError: Object [object Object] has no method 'get'
I’d be grateful of some feedback!
You can’t use
namein that context, you’re running intowindow.name. If you start from scratch without the lowercase name variable you should run just fine. Also, fencliff makes good points in how to use default inheritance.