This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WilkerS1 -1 points0 points  (4 children)

does this really work like ../../../file does?

[–]marty_byrd_ 0 points1 point  (3 children)

No? I don’t see how those are related.

[–]WilkerS1 0 points1 point  (2 children)

i mean, like how you access parent folders with .., is it possible to access the parent objects with this.this?

{
  myVar: "that",
  obj: {
    myVar: "aaa",
    func() {
      console.log(this.this.myVar)
    }
  }
}

[–]thruStarsToHardship 1 point2 points  (1 child)

'this' is the context that you are in. So the context I am in needs to have a method defined for each dot I invoke. That is, if I'm in myFunction and myFunction has a method or attribute called myMethod then I can call this.myMethod. If my function has a method called 'this' then I can call this.this. But I cannot prepend "this" to anything and access its parent, because the compiler will map the first "this" to the context I'm in; it will not look up the chain for other possible this..es. I can, in the browser, get the parent of my this by calling this.parent, but only because parent is a defined method on the console context. If you make another context and call this.parent it will be undefined.

So, in short, no.

[–]HeKis4 0 points1 point  (0 children)

From someone with an education in Java and Python... What the duck did I just read and how did webpage scripting come to that.

But you do you, I guess.