当你这样说时:
VV = V.extend({q: 234});
您正在创建VV
的“子类”V
将具有额外的q
属性。“类”定义的属性与View#initialize
.
如果它说“创建视图的新实例”,文档可能会更好。
然后,当你在其单个参数中传递给视图的方法时new VV({z: 123})
({z: 123}
1.1.0之前的 Backbones 自动设置为构造函数的选项),你应该看起来更像这样:initialize
options
this.options
q
this.q
initialize
initialize: function(options) {
console.log(options.z);
console.log(this.q);
}
另外,如果你这样做:
var VVV = VV.extend({q: 'pancakes'});
您将替换get和insideq
实例的默认值。VV
this.q
'pancakes'
initialize
演示:http: //jsfiddle.net/ambiguous/eqBV2/
Using View#extend
is like subclassing (or more accurately it creates a new prototypical instance) whereas new
creates new objects (or copies of the prototypical instance). Of course, the class/instance language doesn't fit the reality of JavaScript so we have to be careful not to take the terminology too seriously.