Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Created June 23, 2014 04:16
Show Gist options
  • Select an option

  • Save adammcarth/661e29a2859dc28e6018 to your computer and use it in GitHub Desktop.

Select an option

Save adammcarth/661e29a2859dc28e6018 to your computer and use it in GitHub Desktop.
function Foo( callback ) {
this.callback = callback;
}
Foo.prototype.Bar = function() {
xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
console.log(this.callback);
// => undefined
}
xhr.onreadstatechange = function( this ) {
console.log(this.callback);
// => Uncaught TypeError: Undefined is not a function.
}
xhr.onreadystatechange = function() {
console.log(Foo.callback());
// => Uncaught TypeError: Undefined is not a function.
}
// Hmmm....
// How can I get Foo's calback argument?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment