JavaScript CONSTRUCTORS in 5 minutes! 🛠

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2023
  • #JavaScript #tutorial #course
    // constructor = special method for defining the
    // properties and methods of objects
    function Car(make, model, year, color){
    this.make = make,
    this.model = model,
    this.year = year,
    this.color = color,
    this.drive = function(){console.log(`You drive the ${this.model}`)}
    }
    const car1 = new Car("Ford", "Mustang", 2024, "red");
    const car2 = new Car("Chevrolet", "Camaro", 2025, "blue");
    const car3 = new Car("Dodge", "Charger", 2026, "silver");
    car1.drive();
    car2.drive();
    car3.drive();
    console.log(car1.make);
    console.log(car1.model);
    console.log(car1.year);
    console.log(car1.color);
    console.log(car2.make);
    console.log(car2.model);
    console.log(car2.year);
    console.log(car2.color);
    console.log(car3.make);
    console.log(car3.model);
    console.log(car3.year);
    console.log(car3.color);

ความคิดเห็น • 28

  • @BroCodez
    @BroCodez  7 หลายเดือนก่อน +7

    // constructor = special method for defining the
    // properties and methods of objects
    function Car(make, model, year, color){
    this.make = make,
    this.model = model,
    this.year = year,
    this.color = color,
    this.drive = function(){console.log(`You drive the ${this.model}`)}
    }
    const car1 = new Car("Ford", "Mustang", 2024, "red");
    const car2 = new Car("Chevrolet", "Camaro", 2025, "blue");
    const car3 = new Car("Dodge", "Charger", 2026, "silver");
    console.log(car1.make);
    console.log(car1.model);
    console.log(car1.year);
    console.log(car1.color);
    console.log(car2.make);
    console.log(car2.model);
    console.log(car2.year);
    console.log(car2.color);
    console.log(car3.make);
    console.log(car3.model);
    console.log(car3.year);
    console.log(car3.color);
    car1.drive();
    car2.drive();
    car3.drive();

  • @amitd1572
    @amitd1572 4 หลายเดือนก่อน +3

    Well explained. Possibly one of few videos to cover it so well.

  • @michellegutierrez4690
    @michellegutierrez4690 3 หลายเดือนก่อน

    Thank you for sharing it! It was easy to understand ! Keep up the good work!

  • @jakobo5521
    @jakobo5521 4 หลายเดือนก่อน

    Simple as that. This is what I was looking for. Thanks a lot!

  • @bamidelekarimu1218
    @bamidelekarimu1218 3 หลายเดือนก่อน

    Thanks for taking the time to share this. Very explicit; it was so difficult tfor me to understand this term. Now it's clear to me; thanks indeed.

  • @Sunny-uk5fz
    @Sunny-uk5fz 5 หลายเดือนก่อน

    This was super helpful. Thanks Bro!

  • @RedHeadphones
    @RedHeadphones 6 หลายเดือนก่อน

    dude, i love your videos, you wont believe how much better you taught me javascript than those 12 hour courses

  • @RABWA333
    @RABWA333 2 หลายเดือนก่อน

    thanks a lot, quite clear

  • @tomlaskar4226
    @tomlaskar4226 หลายเดือนก่อน

    Thank you.

  • @lunasoleil2827
    @lunasoleil2827 5 หลายเดือนก่อน

    Very helpful video

  • @GameEdrin
    @GameEdrin 6 หลายเดือนก่อน

    Thanks brother

  • @osmane888
    @osmane888 3 หลายเดือนก่อน +1

    thanks a lot dude ! Your videos already helped me understand some SQL concepts (that i needed for my classes) and now you helped me with that concept. Your explainations are crystal clear because it's explained in simple words and are exhaustive, so thanks !

  • @hmed-Albably
    @hmed-Albably 2 หลายเดือนก่อน

    creative as usual

  • @JuliusIkebiagbo
    @JuliusIkebiagbo 6 หลายเดือนก่อน

    please which software do you use for screen recording?

  • @SupraYoungblood
    @SupraYoungblood 3 หลายเดือนก่อน +1

    Is there a reason why you did not use ES6 Class Constructor?

  • @GordonChao0508
    @GordonChao0508 4 หลายเดือนก่อน

    Does JavaScript constructor method similar with Python “self” method?

  • @user-cz5pp8hw9b
    @user-cz5pp8hw9b 6 หลายเดือนก่อน

    Hii sir,
    Which JAVA version is best for beginners -> JAVA 17 or JAVA 21 in 2023

  • @banjoller
    @banjoller 4 หลายเดือนก่อน

    pls make tut in node.js

  • @manoelribeiro8310
    @manoelribeiro8310 6 หลายเดือนก่อน

    Bro can you teach us Laravel pls?🥺

  • @EledeRR
    @EledeRR 7 หลายเดือนก่อน +5

    When you say "I gotta explain constructers" it sounds like you're being forced

    • @szymonpiechutowski2340
      @szymonpiechutowski2340 7 หลายเดือนก่อน +1

      Hahaha, we are so dumb that he has to

    • @BroCodez
      @BroCodez  6 หลายเดือนก่อน +5

      send help!

  • @szymonpiechutowski2340
    @szymonpiechutowski2340 7 หลายเดือนก่อน

    Did you use a function to create Car because the only other way to create a template for an object is class?

    • @BroCodez
      @BroCodez  6 หลายเดือนก่อน +1

      I talk about classes in the next video

  • @jayroche135
    @jayroche135 หลายเดือนก่อน

    I can't get over... "this." Pun very intended... but seriously... why do we have to set "this.year = year"
    "this.model=model"
    Like... I am not understanding that...

    • @holy_shushcabin3716
      @holy_shushcabin3716 หลายเดือนก่อน

      Nice pun. this. is also seen in C++ (this->), and it helps when you don’t want to come up with a name for a parameter (which is one of the hardest feats in programming). this. also refers to the current instance of the class or object.

  • @WitchDimension
    @WitchDimension 13 วันที่ผ่านมา

    The way people break down constructors is very onfusing