A Beginner's Guide to JavaScript's Prototype

Tyler McGinnis on October 09, 2018

You can’t get very far in JavaScript without dealing with objects. They’re foundational to almost every aspect of the JavaScript programming langua... [Read Full]
markdown guide
 

This is a great and thorough explanation. I wish I could flex my JS more but I just don't get the opportunities. All I can do is read articles nlike this and hope it stays in my head until it might be needed.

 

Just pretend to explain to someone else the same concepts you learned in the article. Take note of what you forgot or are having difficulty to explain and to through the concepts again, repeat until it sticks.

 
 
 

I feel like I just watched a Douglas Crockford lecture in reverse!!

This is a great explanation, but just to weigh in from Crockford's perspective, who's very skeptic about both class and new:

  • Historically, prototypal inheritance was meant to be an improvement of classical inheritance. So in his view the addition of class to JS is actually a step backwards. In my view, it is a misnomer because you could've had the same behavior using the word prototype (but sadly that wasn't a reserve word... I'll assume that's the reason why they went with class).
  • His view is that the fads at the time of its creation influenced JavaScript's addition of the new keyword to create the pseudo-classical inheritance mode, which should've never been there.
  • A problem with the new operator is that if you create a function that requires it but then you forget to type it in, you will pollute the global object instead of creating a new one. That's the reason why constructors are capitalized by convention, so people get used to expecting a new there.
  • Object.create, the method that provides the true prototypical inheritance, wouldn't be added until ECMAScript 5. So new precedes it by a decade, I believe.
  • But actually, even the concept of inheritance of any kind, he has become pretty skeptical of. His favorite aspect of JS has always been its functional behaviors, lexical scoping, closures, etc, and I think that's what's he advocates for object creation these days.

But, as I said, this was a very thorough explanation. Thanks!

 

"So when you try to access leo.prototype, leo doesn't have a prototype property so it will delegate that lookup to Animal.prototype which indeed does have a constructor property. If this paragraph didn't make sense, go back and read about Object.create above."

I think you meant 'leo.constructor' + 'constructor property'? :)

 

One of the best article I have read about the JS object and how constructor and prototype chain works..thanks Tyler for this article.

 

Good article, thank you!
Very good presentation

 
 

This is an excellent post on explaining prototypes!! Thank you for sharing!

 
 

Cool! Thanks for this post. I am subscribed to your newsletter. All the material is always very helpful.

 
 

Wow... great article, I've been struggling with this till now. Tnx a lot

 

Great article, perfectly explained. I also learned a lot today ! Thanks !

 

Awesome article! A great explanation of often misunderstood concepts in JavaScript.

code of conduct - report abuse