我有一个骨干模型
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;
},
});
我试图像这样扩展
Name = app.Era.extend({ defaults: { value: '' } });
这似乎有效,我在控制台中没有错误。我什至可以实例化一个新名称,但是当我尝试实例化一个新名称时,我收到一条错误消息:
> 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'
我将不胜感激一些反馈!