Class keyword - Object Creation in JavaScript P7 - Fun Fun Function

preview_player
Показать описание
💖 Support the show by becoming a Patreon

The class keyword was added to JavaScript in ES6. On the surface, class seems to works like you’d expect, but if you look just a little closer you’ll see that class is just a thin veil on top of the existing prototypal inheritance model. In this video, I try to convince you that you should focus on learning JavaScript inheritance properly, in order to understand the mechanics of the class keyword in JavaScript.

This series is called Object Creation in JavaScript, and is meant to be a deep dive in how object creation works in JavaScript, the different ways that you can create objects and how it all fits together.

🔗 Series Playlist - Object Creation in JavaScript

🔗 Inline evaluation plugin

🔗 Composition over inheritance

🔗 The ’new’ keyword

🔗 Functional Programming in JavaScript series

🔗 Help translate the show to your language

💛 Follow on Twitch and support by becoming a Subscriber
We record the show live Mondays 7 AM PT

💛 Fun Fun Forum

💛 mpj on Twitter

💛 CircleCI (Show sponsor)
Robust and sleek Docker-based Continuous Integration as a service. I used CircleCI prior to them becoming a sponsor and I love that their free tier is powerful enough for small personal projects, even if they are private. Use this link when you sign up to let them know you came from here:

💛 Quokka (Show sponsor)
Wonder how MPJ evaluates JavaScript inline his editor. Quokka is the answer - use this link when you buy to let them know you came from here:

💛 FUN FUN FUNCTION
Since 2015, Fun Fun Function (FFF) is one of the longest running weekly YouTube shows on programming 🏅 thanks to its consistency and quality reaching 200,000+ developers.

🤦‍♂️ The Failing Together concept is what makes FFF unique. Most coding content out there focus on step-by-step tutorials. We think tutorials are too far removed from what everyday development is like. Instead, FFF has created a completely new learning environment where we grow from failure, by solving problems while intensively interacting with a live audience.

Tutorials try to solve a problem. Failing Together makes you grow as a developer and coworker.

📹 Each show is recorded live on Twitch in a 2-hour livestream on Mondays. The host, assisted by the audience, is tasked to complete a programming challenge by an expert guest. Like in the real world, we often fail, and learn from it. This, of course, reflects what the audience identifies with, and is one of the most praised aspects of the show.

⏯ On Fridays, an edited version of the show is adapted for and published on YouTube.

Content Topics revolve around: JavaScript, Functional Programming, Software Architecture, Quality Processes, Developer Career and Health, Team Collaboration, Software Development, Project Management
Рекомендации по теме
Комментарии
Автор

Great video! It needed a long time to realize that inheritence is not possible in the classical sense (with private members, etc, ...). Now I have found my way out with factory functions and composition and I felt in love with javacript. You should do more videos on this topic! :)

MrRiesable
Автор

I miss you man. Your videos are very funny and straight forward.

johnswanson
Автор

object creation in javascript is my favorite series on youtube

slidewineder
Автор

"Fluffykins is tiny dragon that breaths fire"
-- MPJ

frozen_tortus
Автор

If JavaScript continue to bow down to that new people coming in, we'll have a programming language monster.

viniciusalbuquerque
Автор

Good Monday Morning, the thing I look forward to hearing every week <3

DigitalMonsters
Автор

YES, the world needs more of these videos! ...not a joke and im not being sarcastic, the world actually needs more of this info out there.

efreitorhabibulin
Автор

Thankyou for This video MPJ. I followed you when you made the videos. But I see now. I was not good enough to Get something out of it. This video changes the game for me. Something about the classes felt wrong. I had A problem with method overloading. And that led me in to the path Im on now. Rewriting gigantic class objects to many function and learning the nature of this beast called Javascript. Im looking forward to watch your functional programingseries🙏

AndyRocket
Автор

Private properties trick ? What about this:

const sound = Symbol()
export class Mammal {
constructor() {
this[sound] = "My private sound"
}
}

We can access sound property only when we have access to "sound" const. This is more like "module private" then "class private", but still.

WMTeWu
Автор

Another great video! Thanks for enlightening and entertaining me on a rainy Monday morning in Austin, TX! Really appreciate all your wisdom and insights!

twfahey
Автор

Thank you for a wonderful explanation. Finally, i do feel relieved. That 'class' keyword has been really bothering me and now I'm happy to know that it's actually just a sugar keyword for basic prototypal inheritance.

gchamaa
Автор

I'm kind of doing the opposite. I am a JS beginner, and this idea was fed into me that classical inheritance is bad, by Medium articles by Eric Elliot (i hear he is notorious, but I have no idea if that is the case). So I really became focussed about learning prototypes well (at least it led to something fruitful, eh?), and now that I have a somewhat decent idea of it, it's still quite new for me and I don't wanna confuse myself and ruin my weeks (2 at least) of hard work by trying to understand classes in JS.

So I think I will completely avoid classes for nor, and make do with the old school of using prototypes until I am comfortable with those fully. Then I will move onto classes. So, after covering 6 of the 7 videos on this series, I will pause here, and leave without watching the last one. Hopefully, I will be back before long, when its time, and then finally watch this, and add another tool to my arsenal. Happy learning folks :3

PRATIK
Автор

14:00 Yes. You will.

Funny comparing OOP to meth though. We make people feel less ashamed of OOP by helping them use it, then they don't feel condemned when they ask for help to get off of it. So this clean needle might still serve its purpose.

moistbrownypoints
Автор

Great episode! Whenever talking about JS 'classes' I like to illustrate how it is just really delegation on the prototype chain by screwing with 'extends'. Nothing seals the deal better :D

ViniciusDallacqua
Автор

Thank you for your videos and bright thinking :) You guided me to the right path!

From my experience in some situations functional style really helps to get rid of all that redundancy, which pure OOP on classes brings. When I came to Javascript, I chose Typescript dialect, because I was familiar with C# and PHP. Some solutions are really hard to implement using class inheritance even with combination of composition in context of classes, when we instantiate, then share methods. Often, even in relatively simple tasks, we need to apply OOP patterns (like "Strategy") to avoid duplication and build abstractions properly. But as the result we have huge complexity and much code to read and support. I always thought it's ok to have just one tool (I mean pure classes) to solve almost the entire range of problems, but when I came to FP paradigms I was shocked how simple and elegant solutions can be.

My personal philosophy is to use hybrid solutions, both class programming and functional approach, to get convenient solutions. The process of finding ways to do things simple and clear is very encouraging for me!

vpetevotov
Автор

I had been reading the documentation for JS classes and just couldn't wrap my head around `super()` for some reason. Thanks for explaining it so succinctly and clearly - that super() is effectively the constructor of the inherited classes - and arguments passed into it are passed as into that constructor!

MicahBales
Автор

What are your thoughts on languages that compile down into JavaScript like TypeScript or CoffeeScript? (Especially as TypeScript is used for Angular now)

Ellyll
Автор

Oh, you made me watch all series. And it was great.

eugenea
Автор

This "clean needles" metaphor made me laugh so hard. What a great way to phrase that idea. It's almost like the committee was scheming saying "no, no come to JavaScript. It's a wonderful language. See, we even have classes". But the best part of your phrasing was aligning class inheritance to meth hahaha Best things I've heard in a while! Keep up the great work!

anthonypipkin
Автор

Why did you ditched the paper sheets, mpj?

YurickHauschild