I am working on backbone app. I am adding mousedown
event using backbone which calls select
function. Inside select
function I am setting timeout
which calls another function selection
. In selection
function I want to console currently clicked element
using console.log(this.el)
. However, this.el
is undefined because the this does not refer to my current module. How can I preserve this keyword so that I can use this in selection function?
Here is my code
events: {
'mousedown': 'select',
'mouseup': 'deselect'
},
select: function () {
this.timeoutId = setTimeout(this.selection, 1000);
},
deselect: function () {
clearTimeout(this.timeoutId);
},
selection: function () {
console.log(this.el);
}