What I want to do is create a new variable each time function loadGrid
is called. In the function below, the variable in this case would be datagrid
. The reason why I want to do this is because I'll be creating multiple table objects, and each table object will need its own reference variable to call functions such as filter
to it.
I looked into this solution here: Convert string to variable name in Javascript. However, comments state this isn't best practice in Javascript. Is there a better solution to what I want to achieve?
var loadGrid = function(dbTableName) {
$('#'+dbTableName).on('click', function(e){
$('#tables').find('.active').toggleClass('active');
$(this).toggleClass('active');
DatabaseGrid.prototype.fetchGrid = function() {
// call the PHP script to get the data
this.editableGrid.loadJSON("loaddatacustomers.php?db_tablename=" + dbTableName);
};
var datagrid = new DatabaseGrid();
$("#filter").keyup(function() {
datagrid.editableGrid.filter( $(this).val());
});
e.preventDefault();
});
}