JavaScript Classes Tutorial

Поділитися
Вставка
  • Опубліковано 20 лип 2024
  • In JavaScript you can use the OOP (Object-Oriented-Programming) feature of "classes" to construct objects which are then useful resources for your script/application.
    Learn all about classes in JavaScript in this video.
    ⭐️ Course Contents ⭐️
    ⌨️ (00:00) The Basics
    ⌨️ (14:40) Getters and Setters
    ⌨️ (22:43) Static Methods
    ⌨️ (30:11) Inheritance and Extends
    ⌨️ (40:22) Polymorphism
    ⌨️ (46:00) Classes in Practice
    Learn more about JavaScript in this full course: • JavaScript Basics Course
    🎥Tutorial by dcode. Check out the dcode channel for more great tutorials: / @dcode-software
    🐦dcode on Twitter: @dcodeyt
    --
    Learn to code for free and get a developer job: www.freecodecamp.org
    Read hundreds of articles on programming: medium.freecodecamp.org

КОМЕНТАРІ • 255

  • @dcode-software
    @dcode-software 5 років тому +324

    Sorry about the light theme! I'll promise to use a dark theme for all my future videos 😁

    • @magakz
      @magakz 5 років тому +4

      Which theme is that ?

    • @dcode-software
      @dcode-software 5 років тому +7

      @@magakz from memory that one is the Brackets Light theme

    • @ahmedk575
      @ahmedk575 5 років тому +5

      light theme is better for people with sight problems

    • @clarkrc82
      @clarkrc82 5 років тому +38

      Yeah but light theme causes sight problems for those of us who DONT have sight problems lol

    • @tharindadivakara2881
      @tharindadivakara2881 5 років тому +3

      I know it sounds odd, but I work with light themes. 😅 And this theme is really good!

  • @karinmeersman5123
    @karinmeersman5123 5 років тому +52

    beautifully explained. I especially appreciate the fact that you show how classes can be used in real situations. Often that is missing and then the explanation will not stick. I loved it!

  • @user-hs6tg6zy4e
    @user-hs6tg6zy4e 11 місяців тому +8

    I've been studying for 6 months. I aspire to be a web developer.
    In my 6 months, of all the topics i had to learn, this was the best teaching video I've watched. Also, I never comment, but this time I had to.
    Thank you,

  • @jacobwilsh8517
    @jacobwilsh8517 2 роки тому +8

    This was a great tutorial. Concise, clear, straight to the point. Thank you

  • @KevinRamirez-vw5kv
    @KevinRamirez-vw5kv 3 роки тому +15

    Best video I've seen on classes. First time they really made sense.

  • @Kayotesden
    @Kayotesden 4 роки тому +5

    A wonderful & comprehensive revision of basics on Classes. I loved it. Thank you.

  • @natashaswan7731
    @natashaswan7731 2 роки тому +1

    This is super helpful! I watched many videos on OOP but this one by far more explanatory than all of them. THANK YOU!!!!

  • @dev4SEO
    @dev4SEO 5 років тому +12

    Thank you. I liked the video, it is good and I've learned quite a bit. Just one thing about the last example of DOM manipulation - it was a bit harder to understand, because I felt that not all was laid out in a clear and correct order, so it was a bit confusing. But still - great job, thanks again.

  • @zeinab_3107
    @zeinab_3107 Рік тому +1

    I searched a lot to find this amazing class toturial. I can't say how thankful I am. It was the best explanation for class on the internet. God bless you❤🙏🏽

  • @starnsboy
    @starnsboy 5 років тому +23

    This is great! Do not be put of by the 1 hour length. Its worth a watch!

  • @RosanaMoreno-vm5df
    @RosanaMoreno-vm5df Рік тому +1

    Thanks a lot for the beginner-friendly classes' lesson!!! It was easy to understand and entertaining to watch

  • @CianaCorto
    @CianaCorto 5 років тому +1

    A very helpful refresher course! Thanks Dom!

  • @PapaWilk
    @PapaWilk Рік тому +3

    on-screen tutorials like this are such a valuable resource. I followed along until the Classes in Practice section. I lost sight of what we were doing and why we would want to be doing it on our website. While I lost sight of the "big picture," the author's attention to detail was impeccable. Good video.

    • @ChrisTian-ox5nr
      @ChrisTian-ox5nr 8 місяців тому

      OOP can be especially beneficial when building complex websites or applications where you need to model different entities, such as users, products, or orders, and their interactions. It provides a clear and structured way to represent and manipulate these entities in your code.

  • @user-tj6ob8jz8h
    @user-tj6ob8jz8h Рік тому

    Enjoyed every second of the tutorial! Especially the practice part. Thank you a lot ;)

  • @TomFoley247
    @TomFoley247 2 роки тому

    Thank you so much. I've found this playlist to be the best JS Classes tutorial out there.

  • @frankylopez4477
    @frankylopez4477 3 роки тому +1

    Thanks, i liked it a lot. Its really concise and easy to understand. This help a lot for the basics.

  • @fatemeetsluck
    @fatemeetsluck 3 роки тому

    This video inspired me to add get and set properties to my own scripting language. Great video as always!

  • @pedrolelis7854
    @pedrolelis7854 2 роки тому

    Amazing content! Well explained, just to the point! Thanks A LOT!

  • @ingavaiciakauskaite3485
    @ingavaiciakauskaite3485 5 років тому +2

    Great tutorial, excellent explanations, thanks a lot!

  • @limitless1692
    @limitless1692 3 роки тому

    Great video .
    Neat introduction into the Class syntax and all its keywords .
    Thanks !

  • @sumanboi
    @sumanboi 3 роки тому +10

    "the programmer issa special type of person" 36:00 killed me 😂 🤣

  • @thabosiphiwemngoma4772
    @thabosiphiwemngoma4772 2 роки тому +2

    He's name is DOM can there a better teacher for this class? Oh man!!! great class and very constructive lessons(excuse me there). I needed this because I was about to assume that classes were a react.js syntax

  • @sivko23
    @sivko23 5 років тому +95

    who else loves the sound of keyboard?

    • @erniea5843
      @erniea5843 5 років тому +3

      seriously, get a mic!

    • @foxjonesofficial
      @foxjonesofficial 3 роки тому

      Me

    • @jepqmw
      @jepqmw 3 роки тому +1

      sound of keyboard is pretty cool but on white theme background it sucks :'(

    • @xi_red4936
      @xi_red4936 3 роки тому

      It gives me chills lol

  • @djnefrozhardstylepromotion3527
    @djnefrozhardstylepromotion3527 2 роки тому

    Amazing tutorial, makes OOP really easy to dive into !

  • @Fishamble
    @Fishamble 2 роки тому

    Thank you. I very mush appreciated the example with an actual real world implementation of a class.

  • @maujadiprogrammer
    @maujadiprogrammer 3 роки тому +2

    thank you for the tutorial, it really helps me out.

  • @eliasvasques80
    @eliasvasques80 Рік тому +2

    Ohhh, fantastic tutorial, thanks for the lesson!

  • @JamesShisiah
    @JamesShisiah 3 роки тому +2

    This is how front end frameworks are made, from minute #46. Great tutorial

  • @shashankthapa659
    @shashankthapa659 Рік тому +1

    Thank god it took me 10 hours to watch and practice it throughly. Now, Im through! Thanks a lot coach!

  • @pearlsswine
    @pearlsswine 4 роки тому

    Thanks for the video! You did a really good job explaining classes, and I really appreciate using an example at the end of what a class would be used to manipulate the DOM. It actually helps understand the usefulness of classes.

  • @bekhzodbeknematov
    @bekhzodbeknematov 2 роки тому

    a perfect explanation with examples , i would appreciate

  • @burgerxxiii
    @burgerxxiii Рік тому

    I finally conquered javascript classes basics, thanks to you!

  • @user-ke4yx6uw1r
    @user-ke4yx6uw1r 2 роки тому

    Amazing amazing amazing.
    Absolutely loved it.
    Thank you very much.

  • @freecodecamp
    @freecodecamp  5 років тому +4

    Here are some more JavaScript resources:
    JavaScript basics course: ua-cam.com/play/PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5.html
    Another JavaScript course: ua-cam.com/video/_y9oxzTGERs/v-deo.html
    Learn JavaScript in a text-based curriculum: www.freecodecamp.org

  • @markm8090
    @markm8090 3 роки тому +5

    Although I'm close to completing a Udemy course, this vid has helped me to understand this part better. Know that this is an old video, but maybe would be better using dark mode in VS (little difficult for me to see the code on my screen). Thanks, love the tutorials! :)

    • @DineshKumar-jt5tr
      @DineshKumar-jt5tr 2 роки тому

      bro can suggest me good javascript course in udemy for begginer to advance

  • @totfosk
    @totfosk Рік тому

    Dom is the best. The fact that he used underscore on the argements to not get more confusing is key. Most of the tutorials just put this.abc = abc and it's very confusing.

  • @Larreth
    @Larreth 2 роки тому

    The best OOP lesson i've ever taken!

  • @wikylhr
    @wikylhr 5 років тому

    Super easy to understand. Thank you

  • @asyakim5555
    @asyakim5555 2 роки тому

    really understandable. thank you for your work

  • @jrunin
    @jrunin 5 років тому +1

    excelently explained. Thank you.

  • @brightprogrammer
    @brightprogrammer 2 роки тому

    short, compact and to the point

  • @gosinP
    @gosinP 4 роки тому

    What is the keyboard of your choice?
    Thank for the video.
    It will be nice if there are some more practice examples, but either way - it is quite resourceful.

  • @henrysemaganda9587
    @henrysemaganda9587 3 роки тому

    Great video, you have made my career !!

  • @dapolcio3405
    @dapolcio3405 Рік тому

    I think this is the only tutorial on youtube where classes are shown in practice. Other tutorials only show theory so to speak and watching them you don't know how to use this theory in real life application.

  • @schlaus_kwab
    @schlaus_kwab 5 років тому +1

    repeatedly calling the update method when using add() is a bit confusing. Why does it not remove the "dcode" when you add "dog"? Isn't it supposed to remove all the items if there is already a firsChild dcode? Can you please elaborate more on this? Thank you.

    • @armanrozika
      @armanrozika 5 років тому +1

      It is in fact remove all the li tags, but after a (while) loop ends/break, it adds child node to it based on the text that added via push method (notice the for loop after while loop inside update function)

  • @VocalStudioByTen
    @VocalStudioByTen 4 роки тому

    Thank you very much! Very clear!

  • @rossfindlay5375
    @rossfindlay5375 5 років тому

    Great lesson, thanks!

  • @Ali-lm7uw
    @Ali-lm7uw 5 років тому +1

    Nice tutorial. Is there anymore to OOP than this or is knowing this enough?

  •  2 роки тому

    Thanks, I always was scared of classes, but now i see it's not thet hard

  • @MisterAndreSafari
    @MisterAndreSafari 2 роки тому

    Great explaining skills. Thx!!

  • @chriseski
    @chriseski 3 роки тому

    Amazing tutorial, really helpfull. Subscription earned!!

  • @matthewdimicelli4191
    @matthewdimicelli4191 3 роки тому +2

    Can anybody clarify why the coder is using underscores at the beginning of the function parameters (for example, in the constructor methods)? Does this mean that the variables/arguments are not to be used outside of the class (eg. that they are "private" to the class)?

  • @user-ye4lg5im9y
    @user-ye4lg5im9y 3 роки тому

    Great tutorial! Thanks.

  • @dansmar_2414
    @dansmar_2414 2 роки тому +1

    One of the best tutorials!

  • @emmadebarros6214
    @emmadebarros6214 3 роки тому

    Really helpful, thank you!

  • @raghumesta26
    @raghumesta26 5 років тому

    Thank you for your effort!

  • @EsnoFava
    @EsnoFava 6 місяців тому

    Thanks, I hate reading MDN docs, this is so much better.

  • @user-xz8of6pk8q
    @user-xz8of6pk8q 8 місяців тому

    Thank for the explanation. Espcially the real situation.

  • @marcinkalmar9964
    @marcinkalmar9964 2 роки тому

    Very good explanation the name of core concept sound very confusing but when it is explain it turn out it isn't hard to absorb.

  • @charanckck
    @charanckck 3 роки тому

    Thank you bro. Very well understood.

  • @sowmyakonkala1046
    @sowmyakonkala1046 2 місяці тому

    very nice video for the first time it did not feel like its an hour video

  • @tyresew.4233
    @tyresew.4233 5 років тому +8

    This is free information!!!

  • @yadikishameer9587
    @yadikishameer9587 2 роки тому +1

    This might be the first tutorial I have seen that's in bright mode 🤪

  • @wieroaisdfjlkds
    @wieroaisdfjlkds 5 років тому

    What you call "Instance methods" like the getArea method in the rectangle class is actually a prototype method that is shared between all instances of the class.If you were to do something like
    const prototype = Object.getPrototypeOf(myRectangle1);
    prototype.getArea = () => 'i am a new method';
    console.log(myRectangle1.getArea()); // 'i am a new method'
    console.log(myRectangle2.getArea()); // 'i am a new method'
    they would both print out "I am a new method".
    as also shown by the fact that myRectangle1.hasOwnProperty('getArea'); is false
    to be a real instance method the constructor would have to be defined as follows:
    constructor(_width, _height, _color){
    this.width = _width;
    this.height = _height;
    this.color = _color;
    this.getArea = function()
    {
    return this.width * this.height;
    }
    }
    then if we do the following:
    myRectangle1.getArea = ()=> 'i am awesome';
    console.log(myRectangle1.getArea()); // 'i am awesome'
    console.log(myRectangle2.getArea()); // 170
    myRectangle2.getArea() doesn't change this time as it is it's own instance method and this time myRectangle2.hasOwnProperty('getArea'); is true
    also the add method in the listBinding class is not the best example to show, if you have a list of 1000 items and want to add one thing you are doing 1000 deletions and 1001 insertions into the dom which is one of the slowest things you could do.

  • @havefun5519
    @havefun5519 4 роки тому +1

    Thanks for your tutorial, really good.

    • @havefun5519
      @havefun5519 2 роки тому

      Ops, I have watched it 2 years ago, finally I re-watch again.haha

  • @GitGudZ
    @GitGudZ 8 місяців тому

    Great Tutorial. Thanks you very much.

  • @AbhishekKumar-mq1tt
    @AbhishekKumar-mq1tt 5 років тому

    Thank u for this awesome video

  • @fregina3813
    @fregina3813 2 роки тому

    Brilliant class, thx a lot

  • @AkaExcel
    @AkaExcel 5 років тому +2

    Thank You for your useful video!

  • @tuxmusicman
    @tuxmusicman 5 років тому +1

    Fixed my problem with super()! Thank you!

    • @tuxmusicman
      @tuxmusicman 5 років тому

      I'm still having a problem where the class isn't being updated.

  • @zeroxcrusher
    @zeroxcrusher 5 років тому

    Why exactly are we adding underscore before parameter name in constructor() function?

  • @MsSamar2005
    @MsSamar2005 4 роки тому

    excellent tutorial thanks alot

  • @ArmandoPineda4
    @ArmandoPineda4 11 місяців тому

    This was great, thanks!

  • @humayunakhtar2116
    @humayunakhtar2116 5 років тому +1

    Brother I'm getting this error.
    Any help?
    ListBInding.js:14 Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'.

  • @carmelon8917
    @carmelon8917 5 років тому

    Useful lesson!

  • @somilbichpuriya161
    @somilbichpuriya161 4 роки тому

    How to declare a static variable for method... For example ,if I want to count the number of objects created for a class.

  • @joedewhurst6569
    @joedewhurst6569 Рік тому

    This has really helped! thanks :)

  • @himanshuvashist3446
    @himanshuvashist3446 5 років тому

    thank you for this video. :)

  • @knightonhd1144
    @knightonhd1144 5 років тому +1

    Good stuff 👍

  • @SpiritMrKatarsis
    @SpiritMrKatarsis Рік тому

    Classes are challenging 😅 Thanks for the video. Great explanation)

  • @joostvoncken950
    @joostvoncken950 4 роки тому

    You just took me too the next level. Thanks!

  • @IGNACIOLUISGOMEZ
    @IGNACIOLUISGOMEZ 4 роки тому +1

    Excellent video!
    I have a question:
    At minute 59:12 the method "add" is executed. The "add" method has the "update" method inside. Shouldn't the "update" method remove the "firstchild" from the list?
    Thanks for so much teaching!

    • @nouvalkaf
      @nouvalkaf 3 роки тому +1

      "update" method does not remove the "firstchild" anymore within "add" since Dom deleted it at minute 56:18. That eventually the "while" part within the "add" method was not executed.

  • @DineshVutukuru
    @DineshVutukuru 3 роки тому

    Beautiful explanation

  • @larryisenhourii9636
    @larryisenhourii9636 4 роки тому

    Are you using jquery because at the beginning when i do the printDescription, the console shows ${this.width} instead of the width?

  • @emmanuelobonyo291
    @emmanuelobonyo291 2 роки тому

    Thank you for this.

  • @muhammadsafiullah8428
    @muhammadsafiullah8428 5 років тому

    Great tutorial.

  • @jd-king1760
    @jd-king1760 Рік тому

    Hi Dom - excellent video - so informative - the last section with the was so benificical to see how real application of it works - However I'm stuck - can you direct me? I'm looking to nest classes - so with the example you have - each of the having their own class to define/generate them. My application is a Group Menu Kanban style (so columns) and the Cards - looking for that simple explainer how to reference Cards within Columns👍

  • @muhammadjawad9341
    @muhammadjawad9341 Рік тому

    Simple & to the point :)

  • @alijoyce2169
    @alijoyce2169 2 роки тому

    CMD + B and CMD + SHIFT + "+" is what this guy needs in his life.

  • @lesterdimitresque6315
    @lesterdimitresque6315 2 роки тому

    so to sum up what classes (in js) are : they are similar to functions ? but are being used to store objects and values ? did I get that right ?

  • @yashuverma5399
    @yashuverma5399 3 роки тому

    Awesome tutorial

  • @maazahmad9756
    @maazahmad9756 3 роки тому +3

    press 'Window' and '+' key
    then press "Ctrl +Alt + I"
    boom it's dark theme.

  • @sriramnagarajanit
    @sriramnagarajanit 5 років тому +4

    Super explanation :)

  • @codezier2738
    @codezier2738 4 роки тому +1

    Cool video! The syntax moving from Java to this isn't all that different which was my main concern. Since all they teach at school is Java, which we learned JavaScript Instead it has more Freedom and I feel like it has all the concepts we need in real life application (RESTful API JSON) and All front end development is JS so I rlly don't get why we do Java. (Don't get me wrong I like Java but I prefer JavaScript more)

    • @sfafsashfdh6589
      @sfafsashfdh6589 2 роки тому

      2 years passed, have your opinion changed? What are you doing now? Do you have a job as developer?

  • @sonamuhialdeen7866
    @sonamuhialdeen7866 3 роки тому

    Awesome tutorials

  • @ericlanglaismm
    @ericlanglaismm Рік тому

    Dom, what a great name for a web developer!

  • @ThisIsLiving__
    @ThisIsLiving__ 5 років тому +2

    I have a question. Why should i use the classes instead of using a function constructor to create a new object and assign properties and method to it

    • @alsonick
      @alsonick 3 роки тому +2

      It's literally just syntactic sugar, it's just to make the code look much better and cleaner for programmers.

  • @myankpraksh
    @myankpraksh Рік тому

    Thank you so much.

  • @foxjonesofficial
    @foxjonesofficial 3 роки тому

    You can also create functions that start with capital letters and they will create classes
    Example:
    var Person = function(age, name) {
    This.age=age
    This.name=name
    }

    • @amitkumargupta-
      @amitkumargupta- Рік тому

      These are called Constructor function, It's all good but it adds up a little bit of boilerplate when trying to make use of inheritance.