There are times when you are scratching your head wondering how on earth the value of ‘this’ got changed. For example, if you are within a function called from an object, ‘this’ may point to that object. However, when the function is set as an event listener to a button, ‘this’ will be the button itself.
So how can you ensure that ‘this’ binding remains what you want it to be? Here is the code to do just that.