Last active
July 25, 2016 13:56
-
-
Save savelee/eba59a147afd70b2e50226555596e696 to your computer and use it in GitHub Desktop.
Lexical This
This file contains 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
//ES2015 | |
function VideoGame(){ | |
this.title = "Uncharted"; | |
this.version = 3; | |
setInterval(() => { | |
console.log(this.title + " " + this.version++); // |this| properly refers to the VideoGame object | |
}, 5000); | |
} |
This file contains 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
//prior ES2015 | |
function VideoGame(){ | |
var me = this; | |
me.title = "Uncharted"; | |
me.version = 3; | |
setInterval(function() { | |
// The callback refers to the `me` variable of which | |
// the value is the expected object. | |
console.log("1:", this); //Context is Window | |
console.log("2:", me); //Context is VideoGame object | |
console.log(me.title + " " + me.version++); | |
}, 5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment