jQuery this inside each loop
jquery
Solution
make a reference to the "this" that you want to hold onto outside of the loop.
var self = this;
then you can use "self" inside the loop.
Problem
Inside the `initialize()` function there is a jQuery `each` loop. Inside that loop is a reference to `this.dbcolumns` which is obviously not working as jQuery has reassigned `this` to the current loop element. So how can I reference `this.dbcolumns` from inside the loop? It works outside the loop ok. ``` function datatable() { this.url = ''; this.htmltable = ''; this.dbtable = ''; this.dbcolumns = new Array(); this.idfield = 'id'; this.pageno = 0; this.pagesize = 15; this.totalpages = 0; this.totalrecords = 0; this.searchterm = ''; this.initialize = function() { this.dbtable = $(this.htmltable).attr('data-table'); this.dbcolumns.push(this.idfield); $(this.htmltable + ' th[data-field]').each(function(i, col){ this.dbcolumns.push( $(col).attr('data-field') ); /* <<<<<<<<<< this line */ }); return this; } } ```