Prototype, prototype render
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
JavaScript
var Base = function(){};
/**
* Run our data through the template and return an HTML string
* @param {Object} data model attributes
* @return {String} template HTML
*/
Base.prototype.renderTemplate = function(data){
// some rendering code here that uses data
// let's assume magicTemplatingCode returns a string
return magicTemplatingCode(data);
};
/*********************************************************
update_2
**********************************************************/
/**
* Set the template string as our .html property
* @param {Object} data model attributes
* @return {Object} base instance
*/
Base.prototype.render = function(data,arguments_array){
console.log(data,arguments_array);
this.html = this.renderTemplate(data);
this.rendered = true;
return this;
};
// child inherits from base
var Child = function(){};
Child.prototype = Object.create(Base.prototype);
//Child.prototype.constructor = Child;
/**
* Do something prior to rendering with our data attributes
* @param {Object} data model attributes
* @return {undefined}
*/
Child.prototype.preRender = function(data){
console.log("aaa");
// we do something here before the template is rendered
// assume this method returns nothing of importance
};
/*********************************************************
update_1
**********************************************************/
Child.prototype.render = function(){
//As required, it needs to call preRender()
this.preRender();
//Bonus points
this.constructor.prototype.render.apply(this,arguments_array);
// or this.constructor.prototype.render.call(this,arguments);
return this;
}
var child = new Child();
//test render with two arguments
child.render("arg_1", "arg_2");