Callbacks and this

suggest change

Often when using a callback you want access to a specific context.

function SomeClass(msg, elem) {
  this.msg = msg;
  elem.addEventListener('click', function() {
    console.log(this.msg);  // <= will fail because "this" is undefined
  });
}

var s = new SomeClass("hello", someElement);

Solutions

Solutions:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents