第一个会断
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;
};
如果您使用new
运算符实例化 Backbone.Collection.extend,那么 thevar parent = this
将引用扩展对象,但如果您不使用new
thenvar parent = this
将引用Backbone.Collection
并且由于您只能调用.apply
函数,因此代码将在此处中断:
child = function(){ return parent.apply(this, arguments); };
parent
将是一个对象。Backbone.Collection
是一个函数