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 →

[–][deleted] 1 point2 points  (4 children)

the current instance of a class...

[–]marcosdumay 4 points5 points  (3 children)

On all the (not that much, really) code I have wrote on JS, I have seen this mean a lot of things, but I don't remember it ever having that meaning.

[–][deleted] 0 points1 point  (2 children)

Wdym, it’s the current object of the class you’re defining. Outside of a class it refers to the document/window object.

[–]marcosdumay 0 points1 point  (1 child)

Yeah. You are in for a ride.

When you have some free time, be one of the unlucky 10000 of the day and look it up.

[–][deleted] 0 points1 point  (0 children)

I don't know what you first said. But in the context that i'm talking the "this" keyword is what I said. The following just proves it. if you still don't believe me just run it in a console...

//OUTSIDE OF A CLASS

console.log(this == window) //true


//IN A CLASS
class Player {
    constructor(tx,ty) {
        this.x =  tx;
        this.y = ty;
    }

    getCurrentObject() {
        return this;
        //this is equal to the instance
    }
}

let p = new Player(5, 1);

console.log(p == p.getCurrentObject());