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
関数です