Created
January 14, 2019 01:30
-
-
Save harrisonmalone/1bb5f61dff4aa49307836c79424633af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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