Factory Function vs. Constructor vs. Class - JavaScript Tutorial

preview_player
Показать описание
What is the difference between a Factory Function and a Constructor in JavaScript?

Factory vs. Constructor from the series "10 Things JS Developers Should Know"

This is episode 5 in a 10 part series I’m calling 10 things javascript developers should know but probably don’t. In this series, we’re going to cover some of the most fundamental and important parts of JavaScript that most of us don’t actually know, and barely touch. Today, for episode 5, we’re talking about the differences between Factory Functions and Constructor Functions, when should we use one or the other? Episode 5: Factory vs. Constructor. Let’s go!

All the code from this series is available here:

0:00:00 Intro
0:01:00 Recap: What is a Factory and what is a Constructor?
0:02:02 Differences: Factory Function
0:14:08 Differences: Constructor Function
0:18:04 Why you should use Factories
0:20:30 Classes
0:22:22 Conclusion
Рекомендации по теме
Комментарии
Автор

What is the difference between a Factory Function and a Constructor in JavaScript?

ColorCode-io
Автор

The best decision in my YouTube History was to subscribe to this Guy. His teaching method is just amazing. You should launch your own complete js course, why limit it to 20?😅

dreamer
Автор

Hands down the best teacher I’ve come across on YouTube. Keep producing content!!! Love it

flavour_country
Автор

Thanks for this tutorial series

My key Takeaways from this video

Factory functions, by default, create distinct copies of methods for each object, which can be memory intensive.

Constructors, by using prototypes, share a single method instance among all objects, which is memory efficient.

Constructors enable genuine inheritance, unlike factories that need workarounds for a similar effect.
Why Use Factories:

Simplicity: They're just standard functions without needing the 'new' keyword or dealing with 'this'.

Flexibility: They leverage closures, promoting data privacy by not exposing certain properties or methods directly.

Data Privacy: Properties or methods can be hidden, reducing the chance of unintentional overwrites.

thomaswinterburn
Автор

Why doesn’t this series have millions of views

rjwhite
Автор

I'm happy I found your Javascript videos. Saying a very appreciating thank you from Northern Nigeria for now.

asheradanehi
Автор

underrated channel! I'm watching 10 Things JS Developers Should Know and I'm loving it, you explain everything in such great detail and with nice humor too. TOP NOTCH QUALITY VIDEOS HERE. Keep it going man, I hope this channel gets more subs.

SiRexable
Автор

So funny, love how he doesn't just explain how to create constructors/functions but also gives practical examples of how and why the distinctions are important. Liked and subscribed.

sara
Автор

Following the Odin Project and looking up your videos definitely saves time on certain topics. Very clear and concise

KuramasaXP
Автор

This is the first video I have seen from this channel. Subscribed.

bmehder
Автор

i am usually not commenting but once i saw it has only 25k views i had to come down here and say i've been struggling with these stuff for a while and this series shed light over everything
i really hope more programmers get to see these :D

orrodrigez
Автор

Thank you so much for this series of videos! You explanations are perfectly clear, the editing is amazing and they are super entertaining :)

elielberra
Автор

As someone who wants to work as a developer relations engineer, I love this channel. So informative and so fun! Hope I can make great content like this some day. Very inspiring

gottadance
Автор

Love the flow of this video. Awesome editing work as well. You deserve more subs!! (Here before 6K 😎)

iamseanhahaha
Автор

Wow, I've watched so many videos on this and your explanation is by far the best. deserve way more subs

FrostDrive
Автор

You explained the difference so good! I was struggling to understand the difference since im new to JS. You're the best🙌

zafiroula
Автор

I am currently doing a project for college on constructor functions, and these videos have helped a lot! You are the most clear and concise person to explain all of the parameters of a constructor function. Thank you! :D

stephenreynolds
Автор

Great coverage of the topic and parallels of theory against real-world examples. True scholar and a gentleman in real life, keep it up.

TheAcidMotion
Автор

Grazie Mille per i tuoi video, finally I found someone who knows how to make people understand these tricky things. Bravo, Complimenti davvero! Se vieni in Italia your next espresso is on me!

andreadipasquale
Автор

I came back to this video just to refresh my mind! Thank you once again!

BigSmoke-rw