I hate that I'm doing this but I've just started working with Javascript classes and I can't figure out how to call member functions from member functions. Below is the class I have and when I run this I get the following error in Firefox:
this.addCol is not a function
I've also tried calling the function like this:
Table.prototype.addCol(this,key,value);
but that also didn't work. :-)
Table.prototype.addCol = function(key, values){
this.jquery.children('.columns').append('<li>' + key + '</li>');
}
Table.prototype.setData = function(data){
// store the data for this table
this.data = data;
$.each(data.columns, function(key, value){
this.addCol(key, value);
});
}
function Table (name){
this.name = name;
this.jquery = $('<div class="dbtable"><h3>' + this.name + '</h3></div>');
}
thisdoesn't refer to yourTableobject inside of that anonymous function. Use a normal for-loop and it will work.