JavaScript Factory Functions

preview_player
Показать описание
JavaScript factory functions made simple.

Subscribe for more videos:

Want to learn more from me? Check out my blog and courses:

Рекомендации по теме
Комментарии
Автор

This is a good and clear lesson but I feel like you missed the encapsulation aspect of factory functions and how you can theoretically make methods and attributes private with it. That was the explanation I was looking for after reading some articles about it.

KanecoV
Автор

Very good explanation! As a guy who learned C++ now learning web development, I was trying to do OOP the way you would in C++ but I couldn't figure out how the JSON data I was working with have a variable named 'shoulder-length'. You can't use a hyphen in Classes... Found this video and immediately understood what was going on! I had never heard of factory functions.

kylehofmeister
Автор

Thanks I was a little stuck, this video helped it click. A few other videos I checked out weren't really explaining it simple enough. THANKS!

yummyjackalmeat
Автор

Brilliant! Can I ask why you removed the "location" parameter, I thought that would have been needed?

richochet
Автор

it's so useful, thanks for great teaching!

kengthe
Автор

Thanks, easy to understand even for non english speaking !

elora
Автор

hi, factory pattern is all about creating new instances for different classes in a single method. In this video, you are creating regular functions. Are you sure that this is the right way?

havetocheckhavetocheck
Автор

I've seen this video and the next one, I wanna ask is there an actual advantage that each of them have over the other?

joshel
Автор

Hi! What would you recommend? Factory method or class factory???

eunito
Автор

Hi Mosh, thanks for great videos. I have a question regarding methods. Is the method 'draw' in the above example duplicated on every object creation or is it created on the prototype? If it is duplicated for every object, then why should I favor factory functions?

aswink
Автор

Hi there, by declaring: function createCircle() { .... } aren't you attaching your function to the main Window and as I recall you said that is BAD PRACTICE? since this can create problems with your script if using libraries... or so...?

AndWhatNotFreeVideos
Автор

what do you use?
constructor or factory...

___vijay___
Автор

Has anyone noticed one thing? When you call

createCircle(1).draw();

though, it prints the message 'draw', the type of the draw() function returned in the browser console is 'undefined'. Why is it? Should it not be 'function'? Please explain why.

priyamganguly
Автор

Hi Mosh, great video!
Query: how do you add methods from OUDSIDE the function? Following your example in the video, I have used the below for both factory and constructor functions and it works, but I wonder if there is another way specifically for factory functions?


circle1.anotherDraw = function() {
console.log('Adding a new method');
}

circle1.anotherDraw();

AcidHouse
Автор

Thank you for this video! If anyone could help me though; I understand the javascript code in this video and I understand JS is a scripting language as to why it's in the console. But what is this code drawing? Is it drawing a circle on the screen? Or I guess my question is... where is the circle going to be at?

eryntodd
Автор

I thought the return would end the statement or function there at the top, isnt that how it was supposed to work ?

yonzont
Автор

Previous video in playlist was not about how to create an Objekt and this video I cannot understand because it is abut another Thema 😅

goer_basics
Автор

How is this different to a regular function?

this.channel
Автор

How do we call the location property? Within it, there are two sub properties (x, y) too.

joeyng
Автор

Hey, factory function is similar to C programing Ryt

lowercaseguy