The scope of this is preserved when using the arrow function syntax () => { ... } – here is an example taken from TypeScript For JavaScript Programmers.
var ScopeExample = {
text: "Text from outer function",
run: function() {
setTimeout( () => {
alert(this.text);
}, 1000);
}
};
Note that this.text gives you Text from outer function because the arrow function syntax preserves the “lexical scope”.