I wonder why if i declare a function outside the listener function, this
will be undefined but if i delcare the function inside the listener function this
will be defined..
working:
someClass.each(function(i) {
someClass.eq(i).on('click', (e) => {
var targetClass = this.classList[0],
console.log(targetClass);
});
}); // this will be defined as the clicked class
not working:
someClass.each(function(i) {
someClass.eq(i).on('click', buttonClick)
});
buttonClick = (e) => {
var targetClass = this.classList[0],
console.log(targetClass);
}); // this will be undefined