Первый сломается
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
- это функция