JavaScript Question: When Should I use the Prototype?

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • A recent question prompted this tutorial. You may understand prototypal inheritance, but when should you use it? We address that question with examples.
    Earn SCRIPT while learning. Check it out: allthingsjavascript.com/script...
    Would you like to help keep this channel going?
    allthingsjavascript.com/contri...
    Access to EVERY course (get 2 months free): www.skillshare.com/r/profile/...
    Courses offered on Udemy at a discount (access from my site): allthingsjavascript.com/course...
    Tutorials referred to in this video:
    JavaScript Prototype Playlist: • JavaScript Prototypes
    For more resources on JavaScript:
    www.allthingsjavascript.com
    #javascript #AllThingsJavaScriptLLC

ความคิดเห็น • 13

  • @BlaBlaBlaInDaHouse
    @BlaBlaBlaInDaHouse ปีที่แล้ว

    Great video once again! Thank you for your time

  • @ashishdevade7209
    @ashishdevade7209 2 ปีที่แล้ว

    👍👍👍

  • @tajpouria
    @tajpouria 4 ปีที่แล้ว +2

    Hi, how you become master in javascript various concepts sir?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +10

      These are the steps I would suggest. Take time to learn it. I feel a course or a book is important so you aren't just learning parts. Then work on projects. Challenge yourself. Finally, always continue learning. Never stop learning new things about JavaScript all through this process.

    • @2004helloWorld
      @2004helloWorld 4 ปีที่แล้ว +1

      @@AllThingsJavaScript is there a book(s) you recommend?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +3

      @@2004helloWorld My favorite books can be seen at the bottom of my site: allthingsjavascript.com

  • @ziat1988
    @ziat1988 4 ปีที่แล้ว

    I don't see you explain why this reduce memory

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      Not sure I understand the question.

    • @wahoobeans
      @wahoobeans 4 ปีที่แล้ว +1

      If you create many objects from a function constructor, each instance will designate memory for the attributes and methods. Instead of recreating the same method for every instance, all instances can find the method by looking at the prototype object. All instances share the same __proto__. Thus, this reduces the space for methods from n number of instances to 1.

  • @ProgrammingwithPeter
    @ProgrammingwithPeter 4 ปีที่แล้ว

    Basically when you want to extend the "class" functionality

  • @Serjgap
    @Serjgap 4 ปีที่แล้ว

    you should use a class instead

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +4

      Later in the video I show an example of a class even though I'm not a fan of the class structure. It is simply syntactic sugar that masks the use of prototypes.

    • @bordertone_5138
      @bordertone_5138 4 ปีที่แล้ว

      @@AllThingsJavaScript +1