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


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

  1. I need a little clarification on what is a prototype of what. I think that dog, cat, and prairiedog should all be prototypes of animal, but it's always stated that animal is a prototype of the other three. It's the equivalent of someone telling me that eggs lay chickens. I'm sure you're correct, I'm just missing something.

  2. Now this is how u explain prototype chain. Good stuff.

    It would be even better if u made an empty object wildDog = {}, then Object.setPrototypeOf(wildDog, dog) and then called wildDog.talk() that would be the 'full' proto chain example cause it would call talk up from animal and sound from dog.

  3. 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.

  4. 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.

  5. 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?

Leave a Reply