1枚目は壊れる
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 をインスタンス化するvar parent = thisと、extend オブジェクトが参照されますが、使用しない場合new、thenは andvar parent = thisを参照し、関数でBackbone.Collectionのみ呼び出すことができるため.apply、コードは次のように壊れます。
child = function(){ return parent.apply(this, arguments); };
parentオブジェクトになります。Backbone.Collection関数です