I'm trying to create an object and append a corresponding DOM element to which I'd like to bind an event that triggers a function. My question is: is it possible to access the object's initial values within that binded function?
function Bloc() {
this.DOMel;
this.ID = Math.round( Math.random() * 1000);
this.startPosX;
this.init = function() {
$('#blocs-container').append( '<div class="bloc" data-id="' + this.ID + '"></div>' );
this.DOMel = $('.bloc[data-id="' + this.ID + '"]');
this.DOMel.bind('touchstart', function(e) {
this.startPosX = e.originalEvent.touches[0].pageX;
});
}
}
Here, for instance, I'd like to access and modify this.startPosX within the function bound to the touchstart event.
Is it possible? If not, how should I work around it?
Thanks!