This is a question of general curiosity, I've been teaching myself Object Oriented javascript programming because I like the structure and flexibility it provides, but I have run into an issue that I'm puzzled by more than anything else. Suppose I have the following code:
function total (el,arr,i)
{
this.across = function(el,arr,i) {
$(el).each(function() {
if(!$(this).attr("id"))
{
//-- convert each value to a number and push to items array
arr.push(parseFloat($(this).val()));
i = i++;
}
});
return arr;
};
}
I can create a new instance of total and pass it my element, array, and index parameters, and then call total.across to populate my array and update the index of i like so:
$(document).ready(function (){
var arr = [[],[],[]];
var i = 0;
var el = $("#hourly input");
var t = new total(el,arr,i);
alert(t.across());
});
My question is, once I enter the .each method, the keyword this no longer refers to the instance of total, but now to the element passed in the .each method. How then do I push the value returned to the array passed to the original function. In this example I'm using the arr keyword but that doesn't appear to work. In the example I'm hoping to get the new