Prototype basics – Object Creation in JavaScript P3 – FunFunFunction #46




We’ll go through the absolute basics of the prototype in this video. I’m going to explain why you should learn prototypes, and how they work.

Complete series playlist: “Object creation in JavaScript”
https://goo.gl/ELUE4B

You’re probably used to doing inheritance with classes. JavaScript achieves inheritance using prototypes. The real-world analogy used when teaching classes is a blueprint – you have a blueprint of a building, and you use that blueprint to build buildings. The real-world analogy to a prototype is a delegate, a person that has been elected into office that will act on your behalf.

This video is for you if you are coming from another programming language into JavaScript and you’re already somewhat familiar with object oriented programming. You know what classes and inheritance is, but you’re confused about how object orientation is done in JavaScript.

I’m also active on:
• Twitter https://twitter.com/mpjme
• Medium https://medium.com/@mpjme
• Quora https://www.quora.com/profile/Mattias-Petter-Johansson

Original source


48 responses to “Prototype basics – Object Creation in JavaScript P3 – FunFunFunction #46”

  1. I loved the part where you said… why don't you marry prototypes. :). Please mpj, i would like to know which softwares you use for your web series. I would like to start a video series soon and I'm looking for some tips.

  2. So what I understand is that prototype is like a asking a project manager to do something that he can't do himself and he says ok, then passes it on to the person that has that skill in his team to get the work done.

  3. I suppose that before you set the cat to have the prototype of animal it already had a prototype which was the global erhm…prototype? And as you pointed out a few seconds before the global prototype doesn't have a talk function. So if you then call the cat.poop() function neither the cat, the animal nor the global prototype will have it. Correct?

  4. Sorry, my native language is not English, but when I was first learn prototype, I was confused with a word protoss( A race in Starcraft, which is made by a company call Blizzard). My gut tell me that it maybe has some realtionship with it…One day, Ah ha!

    If you have played that, you will understand my example:
    let's say you choose terrain for example.
    ok, you build a factory to generate marines. this factory can be treat as a Object that has marine prototype. and this Object can generate marines. And each marine initilize with a attack and defence properties, and equeals to 1. This is very important for me to understand prototype, Why? Becasue, the properties which the marine has will be upgrade in the future. that's why I using this case for example. During the game, you might want to upgrade the amys attack proterties. When the research complete. All the marines of you amy, will be upgraded, not only for the marines that hasn't created, but also for the marines that has created.

    if we don't set the properties on prototype, this will only effected on the marines that will create in the futures, not for created marines. So you will think this is not fair. you should research the attack first, then, create marines…if you do want game to be like this. you just need upgrade the factory marine prototype.

    This is the case always in my mind….haha…My life for Aiur!

  5. MPJ, fab video as per usual. You mentioned "setPrototypeOf" is never used in PROD, why is that? Seems handy to me and easier to wrap your head around than the new keyword and the prototype property…

  6. Hello MPJ, you have made some arguments against inheritance in favor of composition. I would like to know if those same arguments apply to prototyping as well. Thank you for your videos, they are very helpful! 🙂

  7. It feels like every prototype tutorial online uses the same super basic example, that never really shows the usefulness or real life application of prototypes.

    Your delegate analogy was great at the beginning but then it was just 15min of basically repeating the same thing.

    I'd really love to see this expanded upon to really show, how and especially when you should use prototypes in real life to make your life easier.

  8. To bring this all together, could you do a vid using prototypes to model the DOM in JS? The examples with traversing up the prototype chain for data makes sense, but the interaction of prototyped functions and instance data isnt.

    Great vids. Thx!

  9. Absolutly hillarious presentation! Prototypes are my family for years. So I know them well. Still I am watching your show just because you are so funny and the same time clear and understandable. So your show is nothing new to me but it helps me to explain things much better to my staff and customers!.

Leave a Reply