re: A Beginner's Guide to JavaScript's Prototype VIEW POST


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!

code of conduct - report abuse