+ 2
Can anyone explain?
var x = 3; var one = { x: 2, two: { x: 1, three: function() { return this.x; } } } var go = one.two.three; console.log(go(), one.two.three());
2 Risposte
+ 3
`var go`
Use of 'var' here indicates that variable <go> is stored as an attribute of 'window' object. For this reason when <go> is invoked, <x> refers the one in 'window' object context. That is the one registered by `var x = 3;`
But when the 'three' method is invoked directly, <x> refers to a member of object 'two'.
I guess that's about it
cmiiw 👌
+ 1
Ipang thank you ;)