Please have a look at the code below.
function deferredClick(f) {
return (function (e) {
var $this = $(e.currentTarget);
console.log('Actual target: ', e.currentTarget);
window.setTimeout(function () {
console.log('Target I get here: ', e.currentTarget);
f.call($this.get(0), e);
}, 1000);
});
}
function clickResponder(e) {
var $this = $(e.currentTarget);
$("#out").html('Clicked - ' + $this.val());
}
$('input[type="button"]').on('vclick', deferredClick(clickResponder));
The idea is to trigger the event handler after some fixed delay. When you run the above code, you will get two logs in console. [JSFiddle demo here - http://jsfiddle.net/D7GTP/ ]
Actual target: <input class="ui-btn-hidden" type="button" value="click me" data-disabled="false">
Target I get here: Document
How come e.currentTarget
is mutating from line 4 to line 7?
Please note: The event in question is vclick
, which is provided by jquerymobile.