What is Constructor Function in JavaScript? - JS Tutorial

Поделиться
HTML-код
  • Опубликовано: 17 июн 2024
  • What are Constructor Functions in JavaScript?
    JavaScript Constructor Functions from the series "10 Things JS Developers Should Know"
    by ColorCode.io, Sina Jazayeri
    Full playlist here: • 20 Things JavaScript D...
    This is episode 4 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 4, we’re talking about Constructors and Constructor Functions, the idea behind them, the problem they solve, and how they're different from Factory Functions. Episode 4: Constructor Functions. Let’s go!
    All the code from this series is available here:
    github.com/ColorCode/js-10-th...
    0:00:00 Intro
    0:01:04 What is a Constructor Function?
    0:02:57 The concept
    0:05:30 The code
    0:09:53 Another example
    0:15:49 Summary
    0:16:48 Outro

Комментарии • 154

  • @ColorCodeio
    @ColorCodeio  3 года назад +17

    What is a Constructor Function in JavaScript? 🎉🕺🏻👨🏻‍💻

  • @paulam.moyano1775
    @paulam.moyano1775 Год назад +26

    I am watching every chapter with the same excitement (and anxiety) as a breaking bad episode. Awesome teaching, thanks 🤯👏

    • @ColorCodeio
      @ColorCodeio  Год назад +6

      Haha this is the best comment I've ever got.

    • @g_pazzini
      @g_pazzini 7 месяцев назад +1

      too bad no mr white 😂😂😂

  • @hrahman3123
    @hrahman3123 2 года назад +18

    This needs 100x more views then it does. Looking forward to the rest of the series when you upload it. Great work!

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Thanks Husam! Next videos dropping next week.

  • @davidwilson-brown6972
    @davidwilson-brown6972 3 года назад +28

    This is super clean. I'm hooked. The layout, the lighting, the pace for new coders (which I definitely am) are spot on. Thanks for creating great content wrapped in a professional package. It really makes a difference.
    If anyone is thinking of subscribing or liking, just stop thinking. Subscribe. Like. Done.

    • @ColorCodeio
      @ColorCodeio  2 года назад +2

      Thank you David

    • @EiandGi8Six
      @EiandGi8Six 10 месяцев назад

      yeah! People like Sina should stop working on projects and teach from kids to adults :D

  • @princessceballos
    @princessceballos Год назад +7

    I'm not sure what i'm more impressed by, your editing or the explanations. Ivy-league like quality education for FREE! Thank you.

  • @lewitness1759
    @lewitness1759 Год назад +1

    Thanks, I didn't even realise there was a difference between constructors and factory functions!

  • @ndavid24
    @ndavid24 9 месяцев назад

    I been on the self taught route and these videos have been by FAR the best out there. Thank you for what you do, WE SEE AND APPRECIATE YOU!

  • @riodannn
    @riodannn 2 года назад +3

    i wanna really thank you, i pass all day long trying to undertand 'this', and you explain like a god, and blow my mind, thanks, keep the good work, please

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Awesome. Thanks for your comment.

  • @EiandGi8Six
    @EiandGi8Six 10 месяцев назад

    GREATE GREAT GREAT THEACHER! Evertything in your video is really accurate, from the graphic the music and timing! it's really rare find people that teach the way you do! Go on! and Thank you!

  • @user-sz5yz3zr7f
    @user-sz5yz3zr7f 4 месяца назад

    amazing tutorial! it was so well explained, thank you! ♥

  • @isaacfidler937
    @isaacfidler937 2 года назад +3

    Loving these, really well put together, the videos look great, and the ideas are really clear. Keep it up 👍.

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Making episode 7 as we speak :) Should be out soon.

  • @CondeAlberto
    @CondeAlberto 2 года назад +1

    An excellent job, mate. 👌🏼
    Subscribed.

  • @NcVelocity
    @NcVelocity Год назад +1

    I like the way you teach and the video quality and the code snippets are way better than someone talking and going through with and just speaking quickly. Good job and thank you!!

    • @ColorCodeio
      @ColorCodeio  Год назад

      Thanks for taking the time to write that

  • @aliissa1058
    @aliissa1058 Год назад

    This was really helpful,Thank you so Much!!!!!

  • @worldwide_wes
    @worldwide_wes 11 месяцев назад

    the funny intro earned my sub...just fell flat on my face in an interview where I was asked to explain one of these...time to brush up

  • @TheCinematicTola
    @TheCinematicTola Год назад +2

    Coolest teacher on RUclips,live the explanation

  • @alex_blue5802
    @alex_blue5802 11 месяцев назад +1

    I'm so hooked on this series. Top notch content and presentation.

  • @johnnyholiday1150
    @johnnyholiday1150 Год назад +2

    Brilliant this is exactly what I needed mate! Wanted to make a memory game using classes for the div elements. This was really helpful. Thank you!! Carry on the amazing job cheers!!!!

  • @tetianazhuchenko2182
    @tetianazhuchenko2182 Год назад +1

    It's the best explanation I've had ever 👍👍👍that a lot

  • @michaeljohnson1576
    @michaeljohnson1576 Год назад +4

    So Sina...I've gone over objects like 4 times and this is the first time I'm seeing that objects create a 'this' variable and returns it when you use the New keyword in a constructor function. Being that that is the case, it really goes well with your teachings of factory functions and kinda trivialized a very hard to understand concept for me. Thank you so much for helping....You got my sub yesterday but if I could do it again, I would :).

  • @omersoncruz1081
    @omersoncruz1081 Год назад +1

    I'm loving your js videos. Pls keep it coming

  • @hunin27
    @hunin27 6 месяцев назад +3

    This tutorial is made so well!! I'm learning javascript from Bro Code but i got a bit stuck on classes, your explanation is amazing!!

  • @LeetCodeSimplified
    @LeetCodeSimplified 3 года назад +1

    Thx again! Your tutorials are really awesome!!

  • @Luispaulino-tp7tv
    @Luispaulino-tp7tv 2 месяца назад +1

    Love your content and the way you aproach everything! keep the good work!

  • @genesipes8532
    @genesipes8532 2 года назад +2

    This is definitely great content. You're a natural.

  • @user-mw5bm2xh9x
    @user-mw5bm2xh9x 7 месяцев назад +1

    thanks for the directions.

  • @error0803
    @error0803 2 года назад +1

    You are a great teacher. Thank you so much!!

  • @Misfittykitty
    @Misfittykitty 2 года назад +1

    Excellent explanation--thank you so much!!!

  • @RaelindaWoad
    @RaelindaWoad 2 года назад +2

    I loved learning about the hidden this in the constructor function. Now this.this and this.that makes this.sense!

  • @erickchavez4551
    @erickchavez4551 2 года назад +1

    Thanks for this video, your content is pure gold! Subscribed.

  • @matt.mattox3518
    @matt.mattox3518 2 года назад +3

    Love your videos! Well done and appreciate all the context! Future video on all the extensions you use on VS?

  • @shaharyair4314
    @shaharyair4314 4 месяца назад +1

    Great explanation! thank you so much

  • @martinmorel2416
    @martinmorel2416 6 месяцев назад +1

    Thanks for this content, I learned a lot!!

  • @kevinmaas7867
    @kevinmaas7867 Год назад +1

    thanks for the explaination sir. hope god bless u

  • @fizruk7644
    @fizruk7644 2 года назад +1

    Thank you so much, I subscribed!

  • @bereketsisay1791
    @bereketsisay1791 Год назад +1

    You are doing an awesome job. keep going man.Its kinda weird you have this little subscribers cause you have such quality contents, but its guaranteed you will blow up with these contents.

  • @awaismohsin345
    @awaismohsin345 Год назад

    Soon big companies will pick you up, They don't know yet how rare diamond you are, Exellent

  • @tigana
    @tigana Год назад +2

    Wow. What a hidden gem of a video

  • @sanjayloncha
    @sanjayloncha Год назад +1

    The way you explain the stuff is just amazing....
    Great content delivery.... Keep going champ 🏆....
    Love form INDIA.♥️

  • @abhishekshrivastava177
    @abhishekshrivastava177 2 года назад +1

    Beautiful.I'm crying.

  • @bilalbeny4172
    @bilalbeny4172 7 месяцев назад +1

    thanks for this video

  • @ankurgupta4696
    @ankurgupta4696 Год назад +1

    I request all the viewers to do like and comment the videos, because the content is really awesome, I am loving the Javascript after watching his videos

  • @raxitlakhatariya5915
    @raxitlakhatariya5915 2 года назад +2

    this guy is hilarious, thank you indeed for clearing my doubt! i like the way of your teaching for newbie like me

  • @dantervil6103
    @dantervil6103 8 месяцев назад +1

    Awesome video thanks 👌👌

  • @Ranbo5
    @Ranbo5 9 месяцев назад +1

    Thanks for another awesome tutorial!
    (Btw I'd make that chef take the first bite...)

  • @rathoreboys
    @rathoreboys 2 года назад +2

    As a viewer I would suggest you to put the link to the playlist of video series, or any other video of your channel that you mention in the description box.
    Your content is great👍👍

  • @chrisdietrich1533
    @chrisdietrich1533 3 года назад +1

    Thanks for this

  • @user-hu8ki2je3h
    @user-hu8ki2je3h 5 месяцев назад

    WOW tu expliques très bien mon gars

  • @kerrydaniels8460
    @kerrydaniels8460 Год назад +1

    Thanks!

  • @badbrother_2023
    @badbrother_2023 Год назад +1

    This is really awesome. React does this

  • @mahdietaghavi3759
    @mahdietaghavi3759 2 года назад +1

    Thanks sina, from iran😊

  • @simonshurety3870
    @simonshurety3870 2 года назад +1

    " Uughh, I'm bored already, who da fuq wrote this s*#t?"
    "You did!"
    🙌

  • @abelmarkos5753
    @abelmarkos5753 2 года назад +1

    hell sina
    very well explanation
    Would yuo consider making another series called
    10 things react developer should now but probably don't

    • @ColorCodeio
      @ColorCodeio  2 года назад

      That would be really cool. Thanks for the suggestion.

  • @mosesmbadi4158
    @mosesmbadi4158 2 года назад

    Love your content man. I think I am ready for that interview now, hehe. Anyway, I love your set up. I am planning to start a RUclips channel, I'm sort of a social Critique, do you have any tips on how to set up something like yours?

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Depends what exactly you need. Message me on Instagram and we chat talk @colorcode.io

  • @heisenbergsk21
    @heisenbergsk21 Год назад

    You have a nice way of explaining things but unique,you wouldn't make anyone bored of even boring top. Even tho I know most of the things you teach still I watch it coz you are too good.

  • @codepearls
    @codepearls 11 месяцев назад +1

    DOM related examples were understandable. ☺☺

  • @Linuxdeveloper
    @Linuxdeveloper 2 года назад +1

    Thanks for the video man, just wondering - what text editor do you use here, once presenting your code?

    • @ColorCodeio
      @ColorCodeio  2 года назад +2

      Chrome DevTools :)

    • @Linuxdeveloper
      @Linuxdeveloper 2 года назад

      @@ColorCodeio Hahaha 😂 I didn't see that coming 😂😂😂 Thanks man 😂

  • @mathanprakash5685
    @mathanprakash5685 2 года назад +1

    You seem like naturally has a teacher

  • @Chris2phaBrown
    @Chris2phaBrown 3 года назад +2

    Cool vid, always good to see videos about different ways to do things that that I once knew, but have probably forgotten, it seems the more I learn about all the new fancy frameworks, the more I forget about basic JS :(
    A couple of things I was thinking about when watching the video..
    What happens when you call the constructor function without the new keyword?
    How is the constructor different from the factory function as far as memory is concerned, I think, if there was a talk function in both the factory and constructor, Each item created with the factory function would have it's own instance of the talk function, but with the constructor, each item would reference a single instance of a talk function... hmm, I could be wrong though lol. I was waiting for you to show the structure of the object created with the constructor to see if the function was placed on the prototype.
    Keep the cool videos coming mate :)

    • @ColorCodeio
      @ColorCodeio  3 года назад

      Chris! Always good to hear from you man.
      At the end of the day Constructor functions are just functions so if you don't use NEW then it'll just execute like any other function, but obviously it won't return the this object back so nothing happens other than what's in the function itself.
      Regarding the memory footprint I think you're right. One of the things I failed to mention in the video is how using constructors you're pointing to a 'source of truth' object where you can add methods to the prototype property and add functionality to your objects that's placed on one object. Where as factory functions don't follow that concept, they're copies of each other every single time. Thanks for pointing that out.
      Thanks again for always watching my stuff. We should catch up soon. Hope you're doing well down under!

  • @Yash-et9ru
    @Yash-et9ru 3 года назад +3

    Please keep continue this series

  • @evilcom
    @evilcom Год назад +1

    thanks

  • @tanmaychotu665
    @tanmaychotu665 2 года назад +1

    why you are not making more content like this??..it's great

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Lots more content coming soon.

  • @VikasChauhan1809
    @VikasChauhan1809 2 года назад

    Please make a series on NodeJS full course

  • @DevlogBill
    @DevlogBill Год назад

    Excellent video! But I had a question? I tend to write my constructor with a class. But I also write the constructor method under the class and even write super. I am still a newbie. Technically I am guessing it is the same?

  • @kresimircosic3753
    @kresimircosic3753 2 года назад +1

    Fantastic content mate.

  • @Edits-rashy
    @Edits-rashy 2 года назад +1

    If John Oliver knew Javascript it would sound like this .... Brilliant!

  • @varunsharma3775
    @varunsharma3775 3 года назад +2

    Voila !! you are amazing!! When are you gonna post another video? I am super excited . Thanks alot.

  • @RezHimself
    @RezHimself Год назад

    What's the difference between constructor function and normal function? We can use the normal one for this example

  • @user-vv9wt7mb7x
    @user-vv9wt7mb7x Год назад

    do you still consider SuperElement as constructor function even if youre not declaring the constructor function?

  • @daubert4892
    @daubert4892 Месяц назад

    Maybe I am missing something but I don’t see the need for constructors, I am always using so-called factory functions to create my new structured objects. The return syntax is very intuitive. I also never use classes.

  • @user-fx6yv7jd2q
    @user-fx6yv7jd2q 5 месяцев назад

    How this is getting binded inside the arrow function

  • @2ru2pacFan
    @2ru2pacFan 7 месяцев назад +1

    Creepy Craig!!! lol 🤣🤣🤣

    • @ColorCodeio
      @ColorCodeio  5 месяцев назад

      He’s trying his best

  • @TsipporahtheExplorer
    @TsipporahtheExplorer Год назад

    Can someone answer why when he did the click event, the elements came back not in order of the array? it returned: a, b, c, b, a, b ???

    • @ColorCodeio
      @ColorCodeio  Год назад

      I just happen to be clicking on the elements in that order. That's not the order they were rendered in. I'm clicking on the elements in a window that you can't see.

    • @TsipporahtheExplorer
      @TsipporahtheExplorer Год назад

      @@ColorCodeio oh awesome. Thanks so much for the reply! You the MVP.

  • @colindante5164
    @colindante5164 2 месяца назад

    why isn't the following syntax used ? Thanks
    For example:
    class Car {
    constructor(brand) {
    this.carname = brand;
    }
    }
    const myCar = new Car("Ford");

  • @rohanagrawal5747
    @rohanagrawal5747 Год назад +1

    Magic🤣🤣

  • @havefun5519
    @havefun5519 Год назад

    Why it's this.el in constructor element rather than this.type = type?

  • @ultronsam1214
    @ultronsam1214 Год назад

    Excuse me, I thought you can't use an arrow function in a direct object method on this keyword?

  • @blalezarian
    @blalezarian 9 месяцев назад

    Great video but work on the typos!

  • @Nodsaibot
    @Nodsaibot Год назад

    JS object constructors are like C templates

  • @cestlavieeee
    @cestlavieeee 2 года назад +1

    its killing me that your face next to the code is a squircle and not a circle, seems radius of the cutout is a bit smaller

    • @ColorCodeio
      @ColorCodeio  2 года назад

      Haha you noticed! It's there to grab the attention of CSS babies.

    • @cestlavieeee
      @cestlavieeee 2 года назад +1

      @@ColorCodeio true:) designer turned coder.

  • @saragholampour8448
    @saragholampour8448 3 года назад +1

    youre so cool 😂

  • @risselify
    @risselify 9 месяцев назад

    Not clear for me , sad. I'm learning Front-end 6 months

  • @dustinhxc
    @dustinhxc Год назад

    Hahahha who the F wrote this!? 😂😂

  • @NiiiGhtyR
    @NiiiGhtyR Год назад

    sina and qoli ? persian much ? lol

  • @hassansyed6087
    @hassansyed6087 Год назад

    I'm not sure why you found it so easy to call the expression on the guy's face "creepy" ?
    He's just a normal chef posing for a picture with a dish he made. What is so creepy about that?
    Don't get caught up in 2023 feminism ideology where every guy, even slightly showing any expression of joy in a picture, is considered to be predatory.
    Good explanations for your JS material but I just didn't appreciate how you put men down like that. Be better.

  • @dssdfsfddsf3761
    @dssdfsfddsf3761 Год назад +1

    "time is Monee" 😂 great talk..
    I just realized how much time i wasted in my life.

    • @ColorCodeio
      @ColorCodeio  Год назад

      Now that you’re saving time hopefully you’ll save some moneeee

  • @chrisdietrich1533
    @chrisdietrich1533 3 года назад +1

    Thanks for this