Javascript inheritance by "extend" -


can't undestand javascript inheritanse using "extend" function.

i try this

 var extend = function (protoprops, staticprops) {     var base = this;      if (protoprops) {         (var prop in protoprops) {             base.prototype[prop] = protoprops[prop];         }     }     if (staticprops) {         (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"]')); 

oh, sorry. when write "var reportssublayoutview = new reportssublayoutview();", expect first template inside "template" attribute of object, second template inside it. please, tell me make mistake. , sorry bad english )


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -