JavaScript object method to add an event listener