So im trying to make objects that have prototype inheritance without the “new” operator using closures.
My code is:
var TABLE=function (tableId) {
var table=(document.getElementById(tableId)||{}),
colName=[],
rows,
cols,
selectedRow;
//private methods
var updateRows=function(){
//Code that updates the number of row of the table
}
updateRows();
//Declare the public methods for the object
var methods={
prototype:{
cols:function () {
return cols;
},
rows:function () {
return rows;
}
}
};
return methods;
}
var table=Table("Inventory")
alert(table.rows()) //I get undefined
alert(table.prototype.rows()) //I get the actual number of rows
What am i doing wrong? Do you think i could use some better way of coding for this
I appreciate all the help.
We have to use the new keyword in case you want to use prototypical inheritance.
The best to use with example :-
http://www.klauskomenda.com/code/javascript-inheritance-by-example/