I have built my own object:
Main.utilities.pool = function (pool) {
var counter=0;
var $form = $(pool);
return {
add_pool_field: function(){
$form.find('#practice_type').change(function() {
if($(this).find("option:selected").val()){
var time = new Date().getTime();
var regexp = new RegExp( $(this).find("option:selected").data('id'), 'g');
$("#items").append('<li class="colorize">' + '<h1>' + this.increment_counter() + '</h1>' + $(this).find("option:selected").data('fields').replace(regexp, time) + '</li>');
}
});
},
increment_counter: function(){
return ++counter;
},
init: function() {
this.add_pool_field();
}
}
}
I call it as such:
var $profile_pool = Main.utilities.pool($('#new_form')).init();
The problem is in the change event, this refers to a select field. However, I want to access the increment_counter function of the actual anynomous object that was returned from the pool function. When I try this.increment_counter(), it thinks this is the html select field, and so it blows up. How can I gain access to that object within the context of the function passed to change?