JS oop objects properties, prototype sample
Автор: Administrator.
function Widget(size,containerId,html,rowNumber){
this.size = size;
this.containerId = containerId;
this.container = $(this.containerId);
this.html = html;
this.rowNumber = rowNumber;
this.rowId = 'row' + this.rowNumber;
}
Widget.prototype = {
render: function(){
this.row = $('#' + this.rowId);
var div = $('<div></div>').addClass('col-md-' + this.size).text(this.html);
if(!this.row.length){
this.row = $('<div></div>').addClass('row').attr('id', this.rowId);
this.container.append(this.row);
}
this.row.append(div);
}
}
var widgets = [];
widgets.push(new Widget(5,'#container','vjvjy',2));
widgets.push(new Widget(3,'#container','343456',1));
widgets.push(new Widget(3,'#container','343456',2));
function Render(){
for(var i = 0; i< widgets.length;i++){
widgets[i].render();
}
};
$(document).ready(Render)