I have a class testClass
and in testClass
there is a getter called testGetter
and a public object called testObject
. In testObject
I have a function nestedFunction
which attempts to call testGetter
but cannot as the scope for this
is in the testObject
. How could I call the getter (or any function) from the object?
class testClass {
get testGetter() {
return "test"
}
testObject = {
nestedFunction : function(){
console.log(this)
return this.testGetter
}
}
constructor()
{
console.log(this.testObject.nestedFunction())
}
}
new testClass()
Output:
{ nestedFunction: [Function: nestedFunction] }
undefined