在阅读骨干网的源代码时,我只是想知道一些 OO。 http://backbonejs.org/docs/backbone.html(搜索“this.parse(attributes);”)
Backbone.Model = function(attributes, options) {
var defaults;
attributes || (attributes = {});
console.log('attributes : ', attributes);
if (options && options.parse) {
//LOOK HERE
attributes = this.parse(attributes);
}
if (defaults = getValue(this, 'defaults')) {
attributes = _.extend({}, defaults, attributes);
}
if (options && options.collection) this.collection = options.collection;
this.attributes = {};
this._escapedAttributes = {};
this.cid = _.uniqueId('c');
if (!this.set(attributes, {silent: true})) {
throw new Error("Can't create an invalid model");
}
delete this._changed;
this._previousAttributes = _.clone(this.attributes);
this.initialize.apply(this, arguments);
};
parse 是如何在原型中使用的?该方法稍后在 _.extend(Backbone.Model.prototype, Backbone.Events, {