I don't completely understand how this works. For example,
var logger = {
x: 0,
updateCount: function(){
this.x++;
console.log(this.x);
}
}
Now, from what I've read, the value of this when updateCount is called as a property of logger should be logger. So why doesn't the code below work?
document.querySelector('button').addEventListener('click', logger.updateCount);
Also, why does this work?
document.querySelector('button').addEventListener('click', function(){
logger.updateCount();
});