13

Has anybody noticed that "this" in JavaScript is sort of a pain in the ass to keep track of? It appears to have identity issues.

Comments
  • 6
    OwO what’s this?
  • 2
    That is ridiculous.
  • 4
    This is this but it's also that and when it's not this it's probably that, or this was replaced by that and that is no longer this.
    I don't even know what I'm thising about anymore.

    You should only use this.foo() When you know what this is.
  • 2
    this can be tricky, but isn't a problem in general...
    use your arrow functions, and don't destructure instance methods and you'll be fine (as long as on es5+)

    if not on es5, then yes, a pain in the ass because you need to save the this value before entering an inner function like array forEach.
  • 3
    Well .... JS in general is a highly inconsisten language, so why do you even wonder?
  • 3
    @mojo2012 that is a very dumb comment. By that logic, you can't never point out anything in any flawed technology because "why are you surprised?"
  • 1
    Oh man, this
  • 3
    I love how `this` in a function in a class does not refer to the class (: truly intuitive
  • 1
    Ever wondered why JS devs use to say "what is this shit"?

    I think "this" should be extended by "that" where "that" somehow refers to something one level up in the hierarchy, would be fun.
  • 1
  • 1
    @ganjaman what? it never refers to the class on any lang, `this` always refers to the instance

    do you even code bro?
  • 3
    @jesustricks you must be fun at parties
  • 2
    @ganjaman
    a black woman in the us has 5 children, michael, michael, michael, michael and michael.
    how does she tell them apart?
    by the last name

    so, yes, i am fun at parties. i was also referencing the "do you even lift bro" meme.

    anyhow you can tell the diff between instance and class right? if you can't then don't pollute with misinformation
  • 2
    @jesustricks when i wrote class, i clearly meant instance and everyone knows that also that was a shit joke, 2/5
  • 0
    @ganjaman Also, women don't like objects because they're into functional programming.
  • 0
    @ganjaman cool man, i will get off your ass, please don't make jokes that can confuse the fuck out of beginners
  • 0
    This is always this in the current scope.
    The issue is you don't know what te scope is because JS sucks due ti being a hacked togheter piece of shit.

    Every new ES version is even worse.

    Tl;dr Fuck JS
  • 1
    @mundo03 every new es version is worse? what the fuck...?

    please elaborate
  • 1
    @jesustricks I meant ever time JS imomement something from ES.

    ES is good.

    JS on the other hand, feels hackier, dirtier, shitier.
    The most shit they add, the more dependencies, bad practices, you need to add to your workflow.

    The environment is shit, the philosophy is shit, the community is shit too.

    And I know, if you are a JS fan, you will defend it, my point is, you are not a JS fan, you are a node fan.
  • 0
    This is a known issue of object oriented languages
  • 0
    I don't really agree with you, if you use JS often it is not that difficult
  • 0
    Psh, only if you're not very good at JS I guess
Add Comment