You have the following options:
1) Use an arrow function:
class ClassName {
// ...
aMethod(){
let aFun = () => {
this.dir;// ACCESS to class reference of this
}
}
}
2) Or the bind()
method:
class ClassName {
// ...
aMethod(){
var aFun = function() {
this.dir;// ACCESS to class reference of this
}.bind(this);
}
}
3) Store this
in a specialised variable:
class ClassName {
// ...
aMethod(){
var self = this;
function aFun() {
self.dir;// ACCESS to class reference of this
}
}
}
This article describes the necessary details about this
and arrow functions in JavaScript.