2014-10-30 75 views
0

我有一個超設置默認的子類骨幹

var mySuperClass = Backbone.Model.extend({ 
    defaults: { ... } 
}); 

var mySubClass = mySuperClass.extend({ 
    defaults: _.extend(mySuperClass.prototype.defaults, { 
     childDefault1: .. 
    } 
}) 

它完美,它覆蓋每一個值,我需要覆蓋,但如果我創建了一個new mySubClassoptions,如:new mySubClass({someDefault: value})someDefaultproperty將不設置。 有什麼想法?

回答

0

使用_.defaults

var SuperBook = Backbone.Model.extend({ 
    defaults: { 
     author: "test", 
     pages: 525 
    } 
}); 

var MiniBook = SuperBook.extend({ 
    defaults: { 
     description: "mini book"    
    } 
}); 

_.defaults(MiniBook.prototype.defaults, SuperBook.prototype.defaults); 


var myModel = new MiniBook({ author: 'default author', description : 'default description' }) 

感謝