class App {
states = {
key: this,
awsm: {
another: function() {
console.log(this);
}
}
render() {
console.log(this); // Here "this" point to the class
this.states.awsm.another(); // "this" will point to immediate enclosing object awsm, which is fine
console.log(this.states.key); // but Here "this" should point immediate enclosing object/class but not happening
}
}
const myapp = new App();
myapp.render();
In render function, console.log(this)
point to class because class is its immediate binding,
simlarly console.log(this.states.key)
should point to its immediate binding, which is states obj.
but that not happening.
I think it will only look for its immediate binding, when this keyword is invoked from the inside of a function. please tell me if i am correct