Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Created January 14, 2019 01:30
Show Gist options
  • Save harrisonmalone/1bb5f61dff4aa49307836c79424633af to your computer and use it in GitHub Desktop.
Save harrisonmalone/1bb5f61dff4aa49307836c79424633af to your computer and use it in GitHub Desktop.
var x = 5,
o = {
x: 10,
doIt: function() {
var x = 20;
console.log(this.x);
setTimeout(function(){
console.log(this);
}, 1000);
}
};
o.doIt();
// in the setTimeout this.x is undefined because this in that context of the setTimeout callback is the timeout object
// if you bind o to the end of that function you then have access to the o object which contains x and the doIt function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment