第一個將打破
var Appointment = Backbone.Model.extend({
defaults: {
"time": "0000",
"note": "This is an appointment"
}
});
var AppointmentList = new Backbone.Collection.extend({
model: Appointment
});
var aptlist = new AppointmentList();
在Backbone.js的,我們有
var extend = function(protoProps, staticProps) {
var parent = this;
var child;
if (protoProps && _.has(protoProps, 'constructor')) {
child = protoProps.constructor;
} else {
child = function(){ return parent.apply(this, arguments); };
}
_.extend(child, parent, staticProps);
var Surrogate = function(){ this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
if (protoProps) _.extend(child.prototype, protoProps);
child.__super__ = parent.prototype;
return child;
};
如果實例Backbone.Collection.extend與運營商new
,那麼var parent = this
將涉及延長對象,但如果你不使用new
然後var parent = this
將參考Backbone.Collection
因爲你只能在函數調用.apply
,代碼將打破在這裏:
child = function(){ return parent.apply(this, arguments); };
parent
會一個東西。 Backbone.Collection
是一個功能