无法使用“extend”功能取消javascript inheritanse。
我尝试这样做
var extend = function (protoProps, staticProps) {
var base = this;
if (protoProps) {
for (var prop in protoProps) {
base.prototype[prop] = protoProps[prop];
}
}
if (staticProps) {
for (var prop in staticProps) {
base[prop] = staticProps[prop];
}
}
return base;
};
var View = function (attributes) {
var _self = this;
attributes = attributes || {};
this.renderTo = function (elem, data) {
var compiled = _.template(_self.template);
var rendered = compiled(data);
$(elem).append(rendered);
};
};
View.extend = View.prototype.extend = extend;
var ReportsSubLayoutView = View.extend({
template: Templates.Reports.SubLayout //FIRST TEMPLATE
});
var ReportsPeriodSectionView = View.extend({
template: Templates.Reports.PeriodSection // SECOND TEMPLATE
});
var reportsSubLayoutView = new ReportsSubLayoutView();
reportsSubLayoutView.renderTo($('[data-dlm-container="main-container"]'));
哦,抱歉。当我写“var reportsSubLayoutView = new ReportsSubLayoutView();”时,我希望第一个模板位于object的“template”属性中,但是第二个模板位于其中。 拜托,告诉我哪里弄错了。 谢谢,抱歉我的英语不好)