im struggling with a script where a method/object returns undefined
var Lang = new function(){
this.get = function(str, trans){
if(TRANSLATE[str]){
var str = TRANSLATE[str][LANG];
if(count_obj(trans) > 0){
for(var key in trans){
str = str.replace('%'+key+'%', trans[key]);
}
}
return str;
}
};
};
function Language(){
this.tbl_list = null;
this.append = function(string, obj, index){
var row = $('<tr></tr>')
.append('<td class="list_row">'+js2txt(string)+'</td>');
for(var key in obj){
row.append('<td class="list_row">'+js2txt(obj[key])+'</td>');
}
var td = $('<td class="list_row"></td>').appendTo(row);
//var inp_edit = $('<input type="button" value="'+Lang.get('BTN_EDIT')+'" />');
alert(Lang.get);
List.append_row(row, this.tbl_list, index);
};
};
alert(Lang.get);
inside the Language object Lang.get returns undefined, but outside it returns the function!?
I don’t see a reason for using new above, it’s just a waste of resources. Since Lang doesn’t seem to be called as a constructor, it should, by convention, start with a lower case letter. Why not:
.
How are you calling it? It appears to be a constructor, so:
Which is the same result as calling
Languageas a function. What is the issue?Also, the jQuery stuff seems to be very inefficient. You might want to work on that. e.g.
would be much better as:
Or even better would be to create a single row with the structure you want, clone it for each row, then just replace the content of the cell.