Это видео недоступно.
Сожалеем об этом.

JavaScript this Keyword Explained Simply

Поделиться
HTML-код
  • Опубликовано: 9 фев 2022
  • In most cases, the value of 'this' is determined by how a function is called. 'this' usually refers to the object that is calling the current function. If a function, foo(), is called from the global scope ("foo()"), then 'this' will refer to the global object - the Window object. But if foo() is called from inside the scope of another object ("devsage.foo()"), then 'this' will refer to the object that is calling foo() - which is the 'devsage' object. Arrow functions don't provide their own 'this' binding so it inherits the 'this' value of the enclosing function.
    📚Materials/References:
    MDN Web Docs: developer.mozilla.org/en-US/d...
    🌎 Find Me Here:
    Twitter: / realdevsage
    Discord: / discord
    Ebooks: payhip.com/devsage
    Merch: cottonbureau.com/people/devsage

Комментарии • 47

  • @DevSage
    @DevSage  2 года назад

    💙 Twitter: twitter.com/realDevSage
    📙 Ebooks: payhip.com/devsage
    💥 Discord: discord.gg/BP8wPv6raA
    👕 Merch: cottonbureau.com/people/devsage

  • @andyryan2945
    @andyryan2945 Год назад +19

    Seriously great explanation! Came here for more clarification on it after The Odin Project lesson Objects and Object Constructors

  • @gameXIII
    @gameXIII 3 месяца назад +4

    'This' references to the object that calling the function.
    This simple sentence cleared my mind after reading a lot of stuff about 'this'. Your explanation is amazing!!

  • @kobudnik
    @kobudnik Год назад +1

    Appreciate all your useful vids. They've substantially benefited me in the first couple months I started out.

  • @user-xm1ve7mr1p
    @user-xm1ve7mr1p Год назад +1

    I've been struggling to fully comprehend this; your video really helped me out. Looking forward to checking out more of your vids ;)

  • @user-hb3lk7bq5z
    @user-hb3lk7bq5z 2 месяца назад +2

    Amazing explanation, much more concise than articles I've read.

    • @DevSage
      @DevSage  2 месяца назад

      Glad it helped!

  • @onagichitchat
    @onagichitchat 10 месяцев назад

    i really want to say thank you because your simple explanation made me get it finally

  • @ArunaTebel
    @ArunaTebel 2 года назад +7

    Thanks a lot. One of the clearest explanations of `this`. 🔥

    • @DevSage
      @DevSage  2 года назад

      No problem, Aruna!

  • @riteshmehta2292
    @riteshmehta2292 Год назад +1

    Very clear explanation ..

  • @charlesE89
    @charlesE89 Год назад

    Great explanation, thank you!

  • @mrjeevy7720
    @mrjeevy7720 10 месяцев назад

    Great explanation, thanks!

  • @flibben
    @flibben 2 года назад +3

    Very clean explanation, thanks for that!

  • @AYUSHSHARMAblogs
    @AYUSHSHARMAblogs 2 года назад +3

    Very nicely explained. Thanks

  • @Affliction604
    @Affliction604 Год назад

    Very good and instructive explanation

  • @trevorjamesconsideracion1982
    @trevorjamesconsideracion1982 6 месяцев назад +1

    Bro, that arrow function confused me while reading an article T - T. Thanks man!

    • @DevSage
      @DevSage  2 месяца назад

      Happy to help!

  • @michi19935
    @michi19935 8 месяцев назад

    Finally someone that doesn't speak overly fast

  • @d0tjs
    @d0tjs 7 месяцев назад

    was very helpful, thanks ..

    • @DevSage
      @DevSage  2 месяца назад

      You're welcome!

  • @a-mok-youb
    @a-mok-youb Год назад

    Is it possible to import any module without writing the module type and export it

  • @Kotovar
    @Kotovar 11 месяцев назад

    Thanks!

  • @taheraalam5156
    @taheraalam5156 7 месяцев назад

    best video on this topic! ty.

    • @DevSage
      @DevSage  2 месяца назад

      No problem!

  • @codify2450
    @codify2450 Год назад

    you are a legend

  • @shivamthemas
    @shivamthemas 6 месяцев назад

    best tutorial on "this" subject

  • @kristhellalvarez1306
    @kristhellalvarez1306 Год назад

    a big thumb up for you, thank you!

  • @GrantH2606
    @GrantH2606 4 месяца назад

    9:53 Could you just use an arrow function with the forEach method/function to solve the "this" problem?

  • @newredroses
    @newredroses 10 месяцев назад +1

    So, could we say that using inline functions with the `this` keyword is discouraged (bad practice) since it would require it being nested within a normal function?
    Meaning that instead of using an inline and nesting it, It's better to simply just use a normal function? Please correct me if I am mistaken! :)

    • @DevSage
      @DevSage  10 месяцев назад +1

      Correct.

  • @spageen
    @spageen 7 месяцев назад

    this is awesome

    • @DevSage
      @DevSage  2 месяца назад

      Thank you

  • @FurkanKARADENIZ-tt8zf
    @FurkanKARADENIZ-tt8zf 20 дней назад

    I am okey with this topic but, i have a question. When i use this keyword on a object literal like 'fullName : this' it says it is a global object and this kind of little things confuses me. Thank you.

  • @KennehGebra-cf9ds
    @KennehGebra-cf9ds 6 месяцев назад

    I subscribed because i was able to understand "this"

  • @Vamsikrishna-mf6ye
    @Vamsikrishna-mf6ye 11 месяцев назад

  • @aloktomar8566
    @aloktomar8566 2 года назад +1

    on forEach (8:02) when this refers to window object why dont we use arrow function for ex: this.hobbies.forEach((hobby)=>{ ( console.log( this.firstName )} ));

    • @abhishekpratap05
      @abhishekpratap05 2 года назад

      You can, i guess he just wanted us to learn how to fix it without changing the callback function type.

    • @hazfrd
      @hazfrd Год назад

      Right , but its more interesting to do that way for the sake of concept and learning isnt ?